Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

Explain the pages in white the expert taxes

Answered: 1 week ago

Question

Does it avoid use of underlining?

Answered: 1 week ago