Homework Assignment 1

This assignment is to be done individually. Do not show your answers to others and do not look at other students' solutions. Prevent other students from accessing your solutions (do not put it in a public library). Provide short and concise answers to the questions below.

Question 1 (Processes, 8%)

a.) What is the purpose of the WNOHANG option of the waitpid (man 2 waitpid) system call?
b.) Explain what happens if a parent process does not 'wait' for the termination of a child process?

Question 2 (Threads, 12%)

a.) Explain the difference between a thread and a process. Name at least two advantages and one disadvantage of threads.
b.) Name four different ways to stop a thread.
c.) Explain why pthread_cond_signal and pthread_cond_wait have to be called while the calling process holds the mutex?

Question 3 (Signals, 20%)

a.) What are the differences between POSIX signals and real-time signals?
b.) Write a program that explores what happens if a signal arrives (same one or different one) while your program is inside a signal handler. Provide the signal handler code used in your program and summarize your results on a Linux computer (mention the kernel version used).

Question 4 (Linux, 10%)

a.) Find the include file for sockets on a Linux system (hint: look at /usr/include/sys/socket.h and possibly at the include files used by this file) and search for a data structure containing the allowed socket types. List them and explain each of them with one sentence.
b.) Find out how many system calls are supported on your Linux system, mention the first one and the last one on the list, the number used for the getpid() system call, and the kernel version of your Linux system (Hint: search for the include file containing this information in the /usr/include directory and its subdirectories).

Question 5 (Performance, 25%)

Write a small program that measures the performance of the getpid() (man 2 getpid) system call and the fork (man 2 fork) system call. Use gettimeofday (man 2 gettimeofday) to measure the system call execution time. Provide the source code (no error handling required) and measure the performance ten times for each of the two system calls and provide the timing results and compute an average for each system call.

Question 6 (Programming, 25% + 5%)

Write a program (no error handling required) that takes a file name as an argument, opens the file, reads it, and closes the file. The file should contain a string with the name of another application (e.g., 'ls' or 'ps' or any of your own applications) and the program forks a new process that executes the application named in the file. Optional: For 5% extra points pass at least one parameter to the application (i.e., the file contains a string such as 'ps -ax' or 'ls -lt').

Submission

The due date for this homework is February 11th, 2005, 11.59pm EST. You will use the drop-off boxes, make a directory called "homework1" and place one single file (.ps, .pdf, .doc, or .txt) into this directory. Your file should clearly relate the answers to the questions (e.g., 'Answer 3a:', etc.). If you made any assumptions or encountered problems with the programming tasks, state these clearly in your document.
Late submissions: Unlike with the programming assignments, late homeworks will absolutely NOT be accepted!