Question: #include #include #include #include #include using namespace std; int main(void) { pid_t childproc; // Process ID of child. pid_t childval; // Return value from waitpid

#include #include #include #include #include using namespace std;

int main(void) { pid_t childproc; // Process ID of child. pid_t childval; // Return value from waitpid call int stat; // Status field when child terminates childproc = fork(); // Create a child process. No error // checking here, which is naughty. if (childproc == 0) { // I am the child int i, j; long sum = 0; for (i = 0; i < 100000; i++) // A buncha makework. for (j = 0; j < i; j++) sum++; exit(0); } else { childval = waitpid(childproc,&stat,__WALL); cout << childval << "'s Status was " << stat << endl; if (WIFEXITED(stat)) cout << "Exited. Process terminated normally." << endl; else if (WIFSIGNALED(stat)) { cout << "Process was terminated with a signal (signal value = " << WTERMSIG(stat) << ")" << endl; } } return 0;

}

Execute the unmodified program and report on the results:

What does it report if you run it to completion without sending any signals?

What does it do/report if you send it a signal 1?

Add a signal handler to the program. In this case, the signal handler should not handle anything for the parent process - just the child process. Code it so that it handles signals 1 - 5.

In this program and in general, what does fork() do?

WIFEXITED and WIFSIGNALED and WTERMSIG are all macros. What do they do and/or report?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!