Question: Consider the following C program. All functions return normally. Make a fork diagram and explain every step. Example how to solve and make a diagram.
Consider the following C program. All functions return normally. Make a fork diagram and explain every step.
Example how to solve and make a diagram.
fork(); printf("Hello "); fork(); printf("Hello "); Now draw the diagram (where H is for the print statement):
+--- H -- | +--- H --+--- H -- | | +--- H -- | | ------+--- H --+--- H --
Actual problem to solve. Make same diagram format one I showed at top for this one.
int pid = 0; void sigchild(int s) { printf("You"); fflush(stdout); if (pid) { kill(pid, SIGHUP); } } void sighup(int s) { printf("are"); fflush(stdout); if (!pid) { kill(getppid(), SIGHUP); } } int main() { int status; pid_t p; Signal(SIGCHLD, sigchild); Signal(SIGHUP, sighup); int i; if ((pid = fork()) == 0) { kill(getppid(), SIGHUP); // getppid returns parents pid sleep(1); exit(0); } sleep(1); if ((p = wait(&status)) > 0) { fprintf(stderr, "silly"); } else { fprintf(stderr, "keep"); } fflush(stdout); return 0; } What is the correct output for the above code?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
