Skip to content

Instantly share code, notes, and snippets.

@smblott-github
Created September 29, 2022 08:03
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 smblott-github/4e8a01cf1389ca5c7d0741ceaf35d3f1 to your computer and use it in GitHub Desktop.
Save smblott-github/4e8a01cf1389ca5c7d0741ceaf35d3f1 to your computer and use it in GitHub Desktop.
Simple zombie (init) process for docker.
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
void term(int signum)
{
printf("TERM: %d\n", getpid());
exit(0);
}
int main(int argc, char *argv[]) {
printf("start: %d\n", getpid());
signal(SIGTERM, term);
while (1) {
int status;
while ( 1 < wait(&status) ) { }
sleep(1);
}
}
@smblott-github
Copy link
Author

smblott-github commented Sep 29, 2022

I have a couple of docker images where I need an init process to reap zombie processes, so I wrote this.

I'm posting it as much to find out if others have better ideas for doing this.

(Should I just be listening for SIGCHLD, rather than polling?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment