// Catch any errors
if (pid < 0) {
fprintf(stderr, "Could not fork(): %m\n");
- exit(EXIT_FAILURE);
// Parent
} else if (pid) {
// Wait until the child process went away
waitpid(pid, &status, 0);
+ if (WIFSIGNALED(status)) {
+ fprintf(stderr, "Child %d was terminated by signal %d\n",
+ pid, WTERMSIG(status));
+
+ return 128 + WTERMSIG(status);
+ }
+
// Pass on the exit code
- return WEXITSTATUS(status);
+ if (WIFEXITED(status))
+ return WEXITSTATUS(status);
// Child
} else {
// Fork again...
return fork_bomb(0, NULL);
}
+
+ return EXIT_FAILURE;
}
static int lines(int argc, char* argv[]) {