Comp111 - Quiz 1 Review 3

Oct 6, 2009 - closed book

Name:________________________________

Login:______________

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) {
    	flag=________1________; 
    	return flag;
        else return 0; 
    } 
    
    must be made ________2________ in some way in order for it to work properly. One can do this either by implementing testset as a specialized machine ________3________ or by preventing the ________4________ 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 ________5________ even though both are trying to lock a resource. The result of this is that the lock does not work, leading to a ________6________ 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 ________7_______ or ________8________ response time. In a(n) ________7________ system, one wants to minimize the time taken to complete all jobs, while in a(n) ________8________ 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 ________9________ or ________10________. For this reason, fopen of a file in a process directory can return ________11________, indicating that the file was not found.
  4. A thread is like a process except that groups of threads share the same ________12________ so that ________13________ switches are faster than for processes. Thread spawning is ________14________ than process spawning. Threads are mostly useful for writing code that is more ________15________ 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;
    pipe(fd);
    if ((pid1=fork())) { 
        FILE *write = ________16________(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 ________17________ while fd[1] is a file ________18________. In the code, the ________19________ process writes data to the ________20________ process, who prints it. The wait3 call is utilized to avoid leaving ________21________ around after ________20_________ processes have finished executing.