Homework 2: Using Unix System Services
This homework (Hints) is given October 3
and is due October 20 by 5pm.
This homework is just a vehicle for using a lot of Unix system services,
thus becoming familiar with them. Look up the Stevens
book and its code to see how these system services work.
Your program generates three children. Thus we have the following processes
PARENT, CHILD1, CHILD2, and CHILD3.
Your program is called with as parameters the names of six text files,
say, fn1, fn2, fn3, fn4, fn5, fn6.
Fn1 and fn2 already exist. Fn3 and fn4 are created by the second process
(first child). Fn5 and fn6 are created by the third process (second child).
Define a function selfid that prints out the process id of the
current process and of its parent.
PARENT:
- Call selfid;
- Call atexit with selfid as parameter;
- Print out all the parameters of the program call;
- Print out all the setenv variables;
- Open for read fn1;
- Spawn the three children processes;
- Close fn1;
- Sleep for 6 seconds;
- Wait for two of its children to terminate and print out
for each child the current time and its process id;
- Exit(0).
CHILD1:
- Call selfid;
- Call atexit with selfid as parameter;
- Open for write fn3 and write to fn3 the lines of fn1;
- Close fn1 and fn3;
- Open for read fn2;
- Open for write fn4 and write to fn4 the lines of fn2;
- Close fn2 and fn4;
- Exit(0).
CHILD2:
- Call selfid;
- Call atexit with selfid as parameter;
- Open for write fn5 and write to fn5 the lines of fn1;
- Close fn1 and fn5;
- Open for read fn2;
- Open for write fn6 and write to fn6 the lines of fn2;
- Close fn2 and fn6;
- Sleep for 15 seconds;
- Exit(0).
CHILD3:
- Call selfid;
- Call atexit with selfid as parameter;
- Execute another program image.
- This program image will:
- prints its own and its parent process id;
- prints the real user id;
- exit(0).
As comment in your program explain:
- Why fn4 and fn6 are each a copy of fn2
while fn3 and fn5 are not each a copy of fn1.
- Explain what happens to the parent CHILD2.
- Why CHILD3 has the same process id and parent process id before and
after the execute statement.
ingargiola@cis.temple.edu