Comp111 - Quiz 1 Review 4 Answers

Oct 6, 2009 - closed book

Name:________________

Login:__________

Please fill in the blanks. Each blank is worth 5 points.

  1. Suppose we have a C function
     
    struct bar *foo(const struct dog *); 
    
    and a function pointer
     
    void *(*p)(const void *); 
    
    Then we can assign the value of foo to p only via a type cast
     
    p = (____(void *)(*)(const void *)____) foo; 
    
    This kind of cast is necessary for starting up a ____thread____, because one wants to pass it an argument of ____unknown/arbitrary/variant____ type.
  2. In the code
     
    pid = wait3(&status,0,&rusage); 
    
    pid is the process identifier of the last process that ____exited/terminated____, while status is that process's ____exit code____.
  3. The command:
     
    pid = fork(); 
    
    creates two copies of a program. In the parent, pid is the identifier of the ____child____, while in the child, pid is ____0____. Failure to flush a formatted I/O output buffer before a fork can lead to ____duplicate/redundant/extra____ output.
  4. The command
     
    execl("/usr/bin/foo", "/usr/sbin/bar", "cat"); 
    
    does the same thing as typing ____/usr/bin/foo cat____ on the command line. It replaces all ____user____ memory with that contained in the new program, but leaves ____kernel____ memory largely alone. Among other things, the program's ____environment____ variable values and I/O ____descriptors____ are preserved after an execl.
  5. Internally, the return values from getrusage are part of the ____process control block____ stored in kernel memory.
  6. Thread mutexes are stored in ____user____ memory while semaphores are stored in ____kernel____ memory. The reason for the latter is that independent processes don't ____share____ memory.
  7. System calls take more time than regular subroutine calls because it is necessary to change the ____context/memory map____ during the call in order to access kernel data structures.
  8. The scheduler decides which process should run next. ____Round-robin____ scheduling minimizes response time for interactive applications, while ____pre-emptive/batch____ scheduling maximizes work throughput.