Created
September 29, 2022 08:03
-
-
Save smblott-github/4e8a01cf1389ca5c7d0741ceaf35d3f1 to your computer and use it in GitHub Desktop.
Simple zombie (init) process for docker.
This file contains hidden or 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 <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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?)