Comp111 - Quiz 1 Review 3 Answers

Oct 6, 2009 - closed book



Please fill in the blanks. Each blank is worth 5 points. Blanks with the same number have the exact same answer. There are 5 points extra credit.

  1. In implementing a binary mutex lock, the testset program
    short flag=0; 
    int testset() {  I
        if (flag==0) {
    	return flag;
        else return 0; 
    must be made ____atomic/uninterruptible____ in some way in order for it to work properly. One can do this either by implementing testset as a specialized machine ____instruction____ or by preventing the ____scheduler/interrupt system____ from interfering with execution during testset by, e.g., executing testset from within the operating system kernel. Without one of these precautions, two calls to testset in different threads can both return ____1/TRUE____ even though both are trying to lock a resource. The result of this is that the lock does not work, leading to a ____race____ condition between the competing processes.
  2. (all blanks numbered 7 or 8 have same answer) One major tradeoff in design of an operating system is whether to improve ____batch_______ or ____interactive____ response time. In a(n) ____batch____ system, one wants to minimize the time taken to complete all jobs, while in a(n) ____interactive____ system, one wants to minimize the time taken to respond to each keystroke from a user.
  3. In assignment 1, the /proc directory contents change whenever processes are ____born____ or ____die____. For this reason, fopen of a file in a process directory can return ____NULL____, indicating that the file was not found.
  4. A thread is like a process except that groups of threads share the same ____memory map____ so that ____context____ switches are faster than for processes. Thread spawning is ____faster/more efficient____ than process spawning. Threads are mostly useful for writing code that is more ____readable/understandable____ than the unthreaded version of the same code.
  5. In the code:
    pid_t pid1, pid2; int status;
    int fd[2]; char buf[1024];
    struct rusage usage;
    if ((pid1=fork())) { 
        FILE *write = ____fdopen____(fd[1],"w");  close(fd[0]);
        fprintf(write, "hi there!\n"); 
        fflush(write); fclose(write);
        pid2=wait3(&status, 0, &usage);
    } else {  
        FILE *read = fdopen(fd[0],"r");  close(fd[1]);
        fgets(buf,1024,read); fclose(read);
        printf("got: '%s'\n", buf);
    write is a file ____pointer____ while fd[1] is a file ____descriptor____. In the code, the ____parent____ process writes data to the ____child____ process, who prints it. The wait3 call is utilized to avoid leaving ____zombies____ around after ____child_____ processes have finished executing.