NEXT UP previous
Next: My Home Page

Answers

  1. In order to do this, you will need to use the select() system call at the top of the infinite loop in main(). In order to be fully effective the socket descriptor inside the SOCKET structure pointed to by sp will also need to be included. As new clients join the chat and existing clients leave, the bits in the read file descriptor set (rdfs) need to be set and reset as appropriate so that select() continually monitors only those file/socket descriptors currently in use.

  2. This just involves using the time() system call to obtain the current time in seconds since 1 January 1970 and then using one of the conversion functions on this value to get a struct tm filled appropriately. The required values can then be extracted from this structure and displayed in the correct date format.

  3. The easiest way to implement this command is just to fork() a child process which will use execvp() to execute the specified command, and then use the times() call in the parent process after waitoing for the child to finish, to obtain access to the child's system and user time information:

    	#include <sys/times.h>
    
    	main(int argc, char **argv)
    	{
    		struct tms tm;
    
    		if (fork())
    		{
    			wait (0);
    			times (&tm);
    			printf("User CPU time = %d.%d secs\n", tm.tms_cutime/10O, tm.tms_cutime%100); 
    			printf("System CPU time = %d.%d secs\n", tm.tms_cstime/100, tm.tms_cstime%iOO);
    		}
    		else
    		{
    			execvp (argv [1], &argv [1]); 
    			exit(1)
    		}
    	}
    


  4. One possible solution is to call the mount and umount system calls with appropriate fixed parameters as follows:

    	/* mountfd0 command - must be setuid root to work */ 
    	main()
    	{
    		setuid(0);
    
    		if (mount("/dev/fd0", /floppy", "ext2", 0, 0)) 
    			puts("moumtfdo failed! ! !\n");
    	}
    
    	/* umountfd0 command - must be setuid root to work */ 
    	main()
    	{
    		setuid(0)
    	if (umount ("/dev/fd0")) 
    		puts ("umountfd0 failed!! !\n");
    	}
    

    The call to setuid(0) is needed to set the real uid of the process to 0, as the mount system call tests the real uid rather than the effective uid when it looks to make sure it is being run by root.


NEXT UP previous
Next: My Home Page