Comp111 - Quiz 1

Oct 2, 2013 - closed book

Name:__Answers__

ECE/CS Linux Login:__couch__

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

  1. After the code fragment:
     
    FILE *f = fopen("foo", "r"); 
    close(0); 
    dup(fileno(f)); 
    
    the program's standard ____input____ is connected to the contents of ____foo (a file)____.
  2. In the call
    pipe(fd); 
    
    fd represents a(n) ____array____ of two ____ints/integers____, where ____fd[1]____ is the write side.
  3. The call:
     
    FILE * f = fdopen(d, "w") 
    
    associates the ____file descriptor____ d with the file ____pointer/stream____ f.
  4. malloc is a(n) ____library____ function while brk is a(n) ____system call____ that malloc calls. In like manner, printf calls ____write____. In this case, buffering is used to ____minimize_____ the number of times that it is called.
  5. A process cannot block except when executing a(n) ____system call_______, and cannot exit of its own choice unless it is ____running____.
  6. The fork system call produces two almost identical copies of the same ____process____. They differ only in the ____return value____ of fork. By contrast, execl replaces the current process with a new one, while preserving ____file descriptors and environment____.
  7. The manner in which one alternates executing processes is called a(n) ____context____ switch. This is usually accomplished by the ____scheduler/kernel____.
  8. The code:
     
    int foo (int i) { return 2*i; } 
    typedef int (*bar)(int); 
    bar none; 
    
    makes ____none____ a pointer to function. To make this an alias for foo, one would write ____none=foo;____.
  9. (Extra credit) In the code immediately above, the lines ____2 (and perhaps 3)____ can appear in a header file, while the others cannot.