Question: Purpose: This assignment covers processes. The programming portion familiarizes you with fork and wait. You may start with a copy of the program {ltt{}/net/326/fork.c}. Modify
Purpose: This assignment covers processes. The programming portion familiarizes you with fork and wait. You may start with a copy of the program {\ltt{}/net/326/fork.c}. Modify the fork so that: 1) If the process is the child, it prints ``C" in front of the number. If the process is the parent, it prints ``P" in front of the number. (Note: you will have to use the if statement from the second fork example.) 2) The loop only goes to 10. 3) If it is the child, just after it prints the number, it sleeps for 2 seconds, if it is the parent , just after it prints the number, it sleeps for 1 second. 4) After the loop, check the command line arguments (see the lecture notes for how to use argc/argv). If there is an argument (other than the name of the file being executed) and you are the parent you should wait for the child to complete. If there is no argument (or you are the child) execute the return immediately. You will know this works if your shell doesn't return until the child is finished (IE, if you can type commands before it's done, the parent isn't waiting). Note: The compiler will warn about implicit declaration of wait/wait3. You will need an additional include to stop this warning (and is good coding practice to do so). See the man page for wait/wait3 to know which include has it.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
