Last active
August 12, 2019 18:15
-
-
Save goshhhy/66a72446e54c6512d5f423451a8ecd5f 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 <thread.h> | |
#include <sys/types.h> | |
#include <sys/wait.h> | |
#include <string.h> | |
int reaper_thread( void *arg ) { | |
int pid, status; | |
while ( 1 ) { | |
pid = wait(&status); | |
switch ( pid ) { | |
case -1: | |
fprintf(stderr, "error reaping child: %s\n", strerror(errno) ); | |
break; | |
case 0: | |
printf("nothing to reap\n"); | |
break; | |
default: | |
printf("reaped pid %i\n", pid); | |
break; | |
} | |
} | |
} | |
int main( void ) { | |
long int r; | |
thrd_t t; | |
/* set up signal stuff ... */ | |
thrd_create( &t, reaper_thread, (void*)r); | |
/* spawn stuff */ | |
} |
this is licensed public domain, CC0, and MIT, use as you need
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if your toolchain doesn't support c11threads, change <thread.h> to "c11threads.h" and download that header file from here:
https://github.com/jtsiomb/c11threads/blob/master/c11threads.h
and link with -lpthread