Skip to content

Instantly share code, notes, and snippets.

@matthiasr
Created April 17, 2012 17:45
Show Gist options
  • Select an option

  • Save matthiasr/2407731 to your computer and use it in GitHub Desktop.

Select an option

Save matthiasr/2407731 to your computer and use it in GitHub Desktop.
shouldn't create zombies
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
int main(int argc, char **argv) {
int pid = 0;
int i;
for( i = 300; i>0; i-- ) {
signal(SIGCHLD, SIG_IGN);
pid = fork();
switch(pid) {
case -1:
exit(1);
case 0:
exit(2);
default:
sleep(1);
}
}
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment