Last active
February 5, 2021 14:23
-
-
Save XanClic/841f1406643fd191dcafdd36449bfbf5 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
#define _POSIX_C_SOURCE 200809l | |
#include <signal.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/wait.h> | |
static void handler(int signum) | |
{ | |
} | |
int main(void) | |
{ | |
sigaction(SIGUSR1, &(const struct sigaction){ .sa_handler = handler }, NULL); | |
pid_t child = fork(); | |
if (!child) { | |
sleep(1); | |
kill(getppid(), SIGUSR1); | |
sleep(5); | |
} else { | |
int status = 0; | |
pid_t ret = waitpid(child, &status, 0); | |
if (ret < 0) { | |
perror("waitpid failed"); | |
} else { | |
printf("(%i, %i)\n", (int)ret, status); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment