ICS412 - Fall 2009 - Homework #2 -

Work alone
You are expected to do your own work on all homework assignments. You may (and are encouraged to) engage in general discussions with your classmates regarding the assignments, but specific details of a solution, including the solution itself, must always be your own work. (See the statement of Academic Dishonesty on the course's syllabus.)

What to turn in?
You can turn your answers on paper on the day the assignment is due (during class or in my office). Alternately you can turn in an electronic copy via e-mail to henric@hawaii.edu and to altunkay@hawaii.edu with a subject line like "ICS412: HW#2" before 11:59PM on the day the assignment is due.


Exercise #1 (10 pts):
Consider the following program:
#include <sys/types.h>
#include <unistd.h>

int main() {
       for ( ; ; ) {
              if (! fork()) { exit(0); }
              sleep(1);
       }
}
What would be an eventual problem if you were to execute this program on your computer? Explain.

Exercise #2 (10 pts):
Consider this program. Assume that the PID of the main process is 33. Each call to fork() in the code is commented to state the PID of the newly created process.

a) For each running process at the time "one" is being printed out on the screen, other than process 33, give its PID, it's PPID, and the PIDs of its children, if any.

b) For each running process at the time "two" is being printed out on the screen, give its PID, it's PPID, and the PIDs of its children, if any.

For both questions assume that all system calls are successful (for brevity, the program does not check error codes.)


Exercise #3 (5 pts):
Consider this (incomplete) program. Based on what we've said in the course, can you think of a reason why this code may be very inefficient? Can you suggest a solution to make it better? This solution would be in the OS, i.e., the implementation of the fork system call. (Nothing can really be done about rewriting the user code.)


henric@hawaii.edu