The Forkin Quiz

  1. What does fork return?
    1. The process ID of the parent
    2. The process ID of the child
    3. A zero
    4. A minus one
  2. Who does the fork?
    1. The client
    2. The server
  3. Suppose I run the program below.  What will it print?  What will I notice about my server when I run it?
  4. main() {
       while(1) {
           int pid = fork();
           if (pid == 1) {
                 cout << 1;
                 exit(0);

           }
       }
    }
  5. Which of these looks like good server code?
  6. pid = fork()
    fd = accept ( ...)
    if (pid == 0)
         handle connect
         exit
    fd = accept( ..)
    pid = fork()
    if (pid == 0) 
        handle connection
        exit
    while(1) 
       pid = fork()
       fd = accept( ... )
       if (fd == 0)
          handle connection
          exit
    while(1)
       fd = accept( .. )
       pid = fork()
       if (pid > 0) 
         handle connection
         exit
  7. What is a zombie?
    1. A process that has called exit but not yet been harvested
    2. A server process that is waiting for a connection
    3. A process that was talking on a socket, but the socket has since died
    4. A server process that ate from undead flesh, and became a livng symbol of Evil in America(tm)
  8. How do you handle zombies?
    _____________________________________________________________________
    _____________________________________________________________________
  9. Suppose that I start the program below.  I notice that it's process 6715.  What is the process number of the process that print "Yooper Scooper"?  And when it runs, what do I notice about the words "yooper scooper"?
  10. main() {
       sleep(10); // wait 10 seconds.  I'm process 6715

       fork();
       cout << "Yooper Scooper!!\n";
    }
  11. List three blocking system calls: ________ ______________ _____________