Question: Objectives: work with signals, fork, waitpid, exit and exit handlers 1 ) Install an exit handler that prints Process PID is exiting where PID is
Objectives: work with signals, fork, waitpid, exit and exit handlers
Install an exit handler that prints Process PID is exiting where PID is obtained by calling getpid
Install a signal handler for SIGCHLD which reaps zombie children using waitpiddetailed below
a waitpid should only be used in this signal handler and wait shouldnt be used in this program
b The handler should update a global count of reaped processes
c Print Parent says: child N reaped where N is the childs exit status
After installing handlers, the process should say Parent says: my PID is PIDPID from getpid
a Parent calls fork N times where N is a macro NUMCHILDREN
b Use a global variable to count forks that is incremented just before each fork
c Save your final program with N but it should work for any value from to
d The parent should not delay in any way such as sleepuntil all forks are completed
The children should print Child says: child N with PID PID exitingN is fork count; PID from getpid
a The child should exit using the fork count as the exit status
The parent should be the last process to exit after reaping all zombie children.
a The parent must print Parent says: exiting at the end of main then exit with status
b To wait for the children to exit, use a loop that checks the global reap count updated by the signal handler. Do not use pause anywhere in the program which waits until a signal arrives this might cause the program to pause forever if its called after the last child is reaped
When declaring variables, use volatile with any global accessed both inside and outside of a signal handler
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
