#include #include #include #include #include #include using namespace std; void TellCase(int c); int main() { pid_t pid; int myCase{0}; for(myCase = 0; myCase < 13; ++myCase) { cout << endl; TellCase(myCase); pid = fork(); if (pid == 0) { switch (myCase) { case 0: return(0); case 1: return(1); case 2: return(2); case 3: return(3); case 4: return(256); case 5: return(257); case 6: raise(1); break; case 7: raise(9); break; case 8: exit(2); break; case 9: _exit(7); break; case 10: abort(); case 11: cout << "Call kill -SIGCONT " << getpid() << endl; raise(SIGSTOP); exit(0); } return 0; } else { bool done{false}; while(! done) { pid_t exitPid; siginfo_t info; exitPid = waitid(P_PID, pid, &info, WEXITED|WSTOPPED|WCONTINUED); if (exitPid == -1) { perror("Wait Failed"); done = true; } else { cout << "A child exited " << endl; cout << "\tThe PID was " << exitPid << " and the fork pid was " << pid << endl; cout << "\tThe uid was " << info.si_uid << endl; switch(info.si_code) { case CLD_EXITED: cout << "\t Wait returned because the child was exited" << endl; cout << "\t Exit staus returned "; cout << info.si_status << endl; done = true; break; case CLD_KILLED: cout << "\t Wait returned because the child was signaled" << endl; cout << "\tThe signal was "; cout << info.si_status << endl; done = true; break; case CLD_STOPPED: cout << "\t Wait returned because the child was stopped" << endl; cout << "\t The stop signal was " << info.si_signo << endl; break; case CLD_CONTINUED: cout << "\t Wait returned because the child was continued" << endl; break; case CLD_DUMPED: cout << "\t Wait returned because the child was dumped core" << endl; done = true; break; default: cout << "\t unable to determine why the wait returned" << endl; } } } } } cout << endl; return 0; } void TellCase(int c){ cout << endl; cout << "Case " << c << endl; switch(c) { case 0: cout << " return(0); " << endl; break; case 1: cout << " return(1); " << endl; break; case 2: cout << " return(2); " << endl; break; case 3: cout << " return(3); " << endl; break; case 4: cout << " return(256); " << endl; break; case 5: cout << " return(257); " << endl; break; case 6: cout << " raise(1); break; " << endl; break; case 7: cout << " raise(9); break; " << endl; break; case 8: cout << " exit(2); break; " << endl; break; case 9: cout << " _exit(7); break; " << endl; break; case 10: cout << " abort(); break; " << endl; break; case 11: cout << " sigstop " << endl; break; case 12: cout << " fallthrough " << endl; break; default: cout << "Unknown case " << endl; } cout << endl; }