Project 2


Write a program in C, or C++ (you may not use the shells or awk) and implement it under UNIX on any UNIX computer (the fedora appliance in VM is recommended). You are strongly advised to follow the project specifications as accurately as you can.

The program behaves as follows:

First it generates a child process called P2. Process P2 is called with its Standard Output connected to a new empty file named “output”.
Next it waits for the P2 process to finish.

Child process P2 behaves as follows.

First it creates its own child process P3 which, after creation, becomes the “ls -al /” command.
Next it creates another child process P4 which, after creation, becomes the “tr -s ' '” command.
Next it creates another child process P5 which, after creation, becomes the “cut -d' ' -f9” command.
Next it creates another child process P6 which, after creation, becomes the “egrep -v '(^\.)|(^$)'” command.
Next it creates another child process P7 which, after creation, becomes the “tr '\n' ' '” command.
The Standard Inputs and Outputs of these programs are to be connected as P3 | P4 | P5 | P6 | P7.

Finally P2 waits for its children P4, P5, P6, and P7 to finish.
Then P2 terminates.

Hint: The effect of P2 would be like running the following complex command: “ls -al / | tr -s ' ' | cut -d' ' -f9 | egrep -v '(^\.)|(^$)' | tr '\n' ' ' > output”.

You should submit a zip file containing all the files including the source, executable, and the “output” file that shows the output of your program.


Note: This project and the previous one are due on June 24, 2007 at 12 p.m. (Jamaica time).