Skip to content

Instantly share code, notes, and snippets.

@XanClic
Last active February 5, 2021 14:23
Show Gist options
  • Save XanClic/841f1406643fd191dcafdd36449bfbf5 to your computer and use it in GitHub Desktop.
Save XanClic/841f1406643fd191dcafdd36449bfbf5 to your computer and use it in GitHub Desktop.
#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