CS360 Final Exam: December 8, 2003

Question 1

The subroutine free() frees a block of memory so that it can be reused by malloc(). However, free() is passed only a pointer to the block to be freed. Answer the following questions about free():

  1. How does free() know how big this block is?
  2. "Bad arguments" can be passed to free(). Describe what a "bad argument" to free() is.
  3. What are the possible results of of passing "bad arguments" to free()?
  4. Free() can be fixed so that "bad arguments" are recognized (or are almost always recognized). Discuss how this can be achieved.

Question 2

Precisely define the semantics of the following two procedures from the pthreads library: (in other words, what do they do?):


Question 3

Write a program that generates SIGPIPE. Note, your program does not have to catch it. It just has to generate it.

Question 4

Write the program pipe. It should do the following. It takes any number of arguments greater than or equal to two:
UNIX> pipe p1 p2 ...
Pipe should execute each program (without arguments), and set up the file descriptors so that standard output of the first program goes to standard input of the second program, standard output of the second program goes to standard input of the third program, and so on.

Pipe should wait for all programs to finish.