Homework 3: Using Unix System Services
This homework (Hints) is given February 14 and is due March 3 by 5pm.
This homework requires you to use Unix system services. 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).
PARENT:
- Print out its own and its parent process id;
- 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 10 seconds;
- Wait for each of its children to terminate and print out
for each child the current time and its process id;
- Exit.
CHILD1:
- Print its own and its parent process id;
- 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.
CHILD2:
- Print its own and its parent process id;
- 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;
- Exit.
CHILD3:
- Print its own and its parent process id.
- Execute another program image.
- This program image:
- prints its own and its parent process id;
- prints the real user id;
- exits.
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.
- Why CHILD3 has the same process id and parent process id before and
after the execute statement.
ingargiola@cis.temple.edu