Created
May 23, 2013 07:09
-
-
Save ariscop/5633217 to your computer and use it in GitHub Desktop.
subreaper, sets PR_SET_CHILD_SUBREAPER so you can have a nice looking process tree in htop
This file contains 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 <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <errno.h> | |
#include <sys/wait.h> | |
#include <sys/prctl.h> | |
int main(int argc, char *argv[]) { | |
if(argc < 2) { | |
puts("Insufficent parameters"); | |
exit(EXIT_FAILURE); | |
}; | |
if(prctl(PR_SET_CHILD_SUBREAPER, 1)) { | |
puts("Failed to become a subreaper"); | |
exit(EXIT_FAILURE); | |
}; | |
if(fork() == 0) | |
execvp(argv[1], &argv[2]); | |
while(errno != ECHILD) | |
wait(NULL); | |
exit(EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment