wait code changed

This commit is contained in:
Ben Harris 2016-11-03 14:45:41 -04:00
parent 9b65fb5473
commit 1568d1035c
1 changed files with 19 additions and 11 deletions

30
bish.cc
View File

@ -123,17 +123,25 @@ int main(int argc, char **argv){
// parent waits for kid to die
else {
int status;
if (wait(&status) == -1) perror("wait error");
if (WIFSIGNALED(status) != 0) {
printf("Child process ended because of signal %d\n", WTERMSIG(status));
}
else if (WIFEXITED(status) != 0) {
printf("\n(%d):", WEXITSTATUS(status));
}
else {
// Program exited abnormally
cout << "Program exited abnormally" << endl;
}
pid_t w;
do {
w = waitpid(kidpid, &status, WUNTRACED | WCONTINUED);
if (w == -1) {
perror("waitpid");
exit(EXIT_FAILURE);
}
if (WIFEXITED(status)) {
printf("exited, status=%d\n", WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("killed by signal %d\n", WTERMSIG(status));
} else if (WIFSTOPPED(status)) {
printf("stopped by signal %d\n", WSTOPSIG(status));
} else if (WIFCONTINUED(status)) {
printf("continued\n");
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
}
}