Comp111 - Quiz 1

Oct 7, 2010 - closed book



Please fill in the blanks. Each blank is worth 5 points. Blanks with the same number have the same answer.

  1. The difference between a file pointer and a file descriptor is that a file pointer has a ________1________ that can be emptied via the fflush subroutine. This is not needed for the file pointer ________2________, which is intended to send error output to the terminal and thus flushes automatically.
  2. In the code:
    if (!(pid1=fork())) { 
        FILE *read = fdopen(fd[0],"r"); close(fd[1]); 
        fgets(buf,1024,read); fclose(read); 
        printf("got '%s'\n",buf); 
    } else { 
        FILE *write = fdopen(fd[1],"w"); close(fd[0]); 
        fprintf(write, "hi there!\n"); 
        fflush(write); fclose(write); 
        pid2=wait3(&status, 0, &usage); 
        printf("exit code for %d is %d\n", pid2, status); 
    The top clause is executed by the ________3________ while the bottom clause is executed by the ________4________ process. For this to work, one must have called ________5________(fd) first. At the end of both clauses, pid1 and pid2 will be ________6________.
  3. Consider the code:
    void handler(int foo) { 
        fprintf(stderr, "got %d\n", foo); 
    signal(SIGINT, handler); 
    registers a signal handler so the process will call ________7________ when the user types the character ________8________.
  4. One of the great controversies of Operating Systems concerns how to ________9_________ runnable processes. ________10________ is suitable for interactive processing, while ________11________ maximizes throughput.
  5. A process contains four main memory "segments". The ________12________ segment contains a read-only version of your program. The ________13________ segment contains variables created by subroutine invocation.
  • A process changes from runnable to ________14________ when it is waiting for some outside event. The ________15________ system call causes it to wait for a specified number of seconds before continuing.
  • The difference between a system call and a library function is that the system call communicates with the ________16________, while a library function calls system calls but does not call the ________16________ directly.
  • The difference between a program and a process is that a ________17________ is a file describing what to do, while a ________18________ is the result of loading that file into memory.
  • CPU usage statistics are measured based upon which processes are ________19________ at specific times. A process that is waiting for something does not consume ________20________ time.
  • Extra credit. The reason that I usually write
    if ((pid==fork()) { 
    rather than
    pid = fork(); 
    if (pid!=0) { 
    is that the former is a bit ________21________.