#include #include #include #include #include #include using namespace std; int main( int argc, char * argv[]) { pid_t pid, wpid; int status; pid = fork(); if (!pid) { // child cout << "I am the child and my pid is " << getpid() << endl; sleep(2); return atoi(argv[1]); } wpid = wait(&status); if(wpid == -1) { perror("Wait"); } else if (wpid != pid) { cout << "Strage things have happened " << endl; } else { if(WIFEXITED(status) ) { cout << "The child exited with status " << WEXITSTATUS(status) << endl; } else if (WIFSIGNALED(status)) { cout << "The child exited wit a singal " << WTERMSIG(status) << endl; } else if (WIFSTOPPED(status)) { cout << "The child was stopped " << endl; } else if (WIFCONTINUED(status)) { cout << "The child was continued " << endl; } } return 0; }