Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <assert.h>
// Test program to ensure OS correctly returns full exit status in si_status member
// of siginfo_t in SIGCHLD handler, as required by POSIX. Linux fails, FreeBSD succeeds.
sig_atomic_t exit_status;
void sigchld_handler(int n, siginfo_t *si, void *v)
exit_status = si->si_status;
int main(int argc, char **argv)
assert(sizeof(sig_atomic_t) >= 2); // enough for 0x1234 test value
struct sigaction act;
act.sa_sigaction = sigchld_handler;
act.sa_flags = SA_SIGINFO;
sigaction(SIGCHLD, &act, NULL);
if (fork() == 0) {
printf("exit status was: %x\n", exit_status);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment