CS360 Midterm -- May 2, 2002

Question 1

For each procedure/system call below, write the letter of the choice to the right that best describes how the procedure/system call returns to its caller.

I. fork() VI. longjmp()
II. exit() VII. pthread_create()
III. execve() VIII. pthread_exit()
IV. signal() IX. pthread_mutex_lock()
V. setjmp()

a. Always returns to the caller.
b. Only returns to the caller when there is an error.
c. Never returns to the caller.
d. Returns to the caller and duplicates the caller's process.
e. May return to the caller multiple times.


Question 2

Part A: Explain exactly what the system call pipe() does. Include the syntax.

Part B: Explain exactly what the system call dup() does. Include the syntax.

Part C: Explain exactly what the procedure pthread_mutex_lock() does.

Part D. Is the following piece of code going to cause a segmentation violation? Explain your answer in detail, including where in the code the segmentation violation occurs if indeed it does occur.

{
  char *s;         /* Line 1 */

  s = sbrk(0);     /* Line 2 */
  *s[1] = 0;       /* Line 3 */
}
Part E: Write a shell command using only the programs cat, head, ls, sort, tail or grep, where one of the processes forked off dies because it catches SIGPIPE. For example, here is a command where the processes all die normally:

UNIX> ls | cat | sort

In you answer, state which process dies by catching SIGPIPE, and why it does so. You may assume that there are two text files in your current directory: f1, which is 30 lines, or f2, which is 1,000,000. Note you can answer the question without using either of these files. You can also specify, it you'd like, that the user must type into the keyboard.