Skip to content

Instantly share code, notes, and snippets.

@ariscop
Created May 23, 2013 07:09
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 ariscop/5633217 to your computer and use it in GitHub Desktop.
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
#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