Skip to content

Instantly share code, notes, and snippets.

@goshhhy
Last active August 12, 2019 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goshhhy/66a72446e54c6512d5f423451a8ecd5f to your computer and use it in GitHub Desktop.
Save goshhhy/66a72446e54c6512d5f423451a8ecd5f to your computer and use it in GitHub Desktop.
#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 */
}
@goshhhy
Copy link
Author

goshhhy commented Aug 12, 2019

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

@goshhhy
Copy link
Author

goshhhy commented Aug 12, 2019

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