Comp111 - Quiz 1

Oct 3, 2018 - closed book



Please fill in the blanks. Each blank is worth 5 points. There are several reasonable answers for some of the blanks; choose one. Blanks with the same number have the same answer.

  1. A difficulty in assignment one is that many system calls cannot be repeated a large number of times, because a different system call must be called between each two calls of the same function. For example, a call to ____pthread_mutex_lock____ must be undone by ____pthread_mutex_unlock____ or a deadlock occurs the next time the former is called. open/close is not an appropriate answer.
  2. During an exec, all ____(user) memory____ is replaced, and the only things that are preserved are the open ____file descriptors/files____ and the ____environment____ variables for the process. In particular, it is impossible to institute a signal ____handler____ before an exec and have it apply to the process after the exec.
  3. A pipe is logically a set of two connected ____file descriptors____ represented as an array of integers int p[2];. Once the pipe is initialized, one writes to p[____1____] and reads from p[____0____]. To write to a pipe as if it were a terminal or file, one uses the library function ____fdopen____ to make fprintf work on the pipe. The differences between write and fprintf include that write acts on a file ____descriptor____ while fprintf acts on a file ____pointer/buffer____. While write always happens ____immediately/when invoked____, fprintf is ____buffered____ and must be ____flushed____ to ensure that everything is written.
  4. The reason that fork and exec are different calls is that one often wants to make changes in process settings ____before____ executing the forked process.
  5. In advanced C, typedefs allows one to define shorthands for complex types. For example, after writing typedef int foo[10]; the typedef declaration ____foo bar;____ declares an array bar with 10 elements. A typedef cannot be ____repeated____ in the same file.
  6. A C pointer to function is used in defining signal ____handlers____ that describe what to do when the signal is received.
  7. A C pointer passed to a function allows the function to ____modify/write to____ the storage where it points.
  8. (Extra credit) In assignment 1, people reported that even pure system calls accumulate a little bit of user time. This is because each system call is implemented via a ____wrapper/user function____ in that actually invokes the kernel function.