Created
March 7, 2019 03:34
-
-
Save ltriant/22afe5d97c1fad98c5eb3d3f987001f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/wait.h> | |
int main(void) | |
{ | |
pid_t pid = fork(); | |
if (pid < 0) { | |
perror("fork"); | |
exit(1); | |
} | |
if (pid == 0) { | |
// Child process, just do nothing | |
while (1) sleep(1); | |
exit(0); | |
} | |
// Parent process, wait on the child proc forever | |
printf("waiting on child pid: %d\n", pid); | |
int status; | |
waitpid(pid, &status, 0); | |
printf("status: %d\n", status); | |
if (WIFSIGNALED(status)) { | |
printf(" SIGCHLD\n"); | |
if (WTERMSIG(status) == SIGTERM) { | |
printf(" child rx'd SIGTERM\n"); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment