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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started