Skip to content

Instantly share code, notes, and snippets.

@NeoCat
Last active August 29, 2015 13:58
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 NeoCat/9982700 to your computer and use it in GitHub Desktop.
Save NeoCat/9982700 to your computer and use it in GitHub Desktop.
Avoid zombie processes on Linux
/*
* Avoid creation of zombie process by child processes.
* build: gcc -O2 ignchld.c -o ignchld
* usage: ignchld bad-command-that-creates-zombie-processes [args ...]
*/
#include <signal.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
signal(SIGCHLD, SIG_IGN);
strncpy(argv[0], "env", strlen(argv[0]));
execv("/usr/bin/env", argv);
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment