Skip to content

Instantly share code, notes, and snippets.

@sitano
Created November 18, 2021 14:46
Show Gist options
  • Save sitano/cf54d94ae6286f97158d3fad9d032939 to your computer and use it in GitHub Desktop.
Save sitano/cf54d94ae6286f97158d3fad9d032939 to your computer and use it in GitHub Desktop.
test reaping caps
#include <stdio.h>
#include <unistd.h>
#include <sys/prctl.h>
int main() {
printf("origin: pid=%d, ppid=%d, pgid=%d\n", getpid(), getppid(), getpgid(getpid()));
printf("prctl %d\n", prctl(PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0));
pid_t pid = fork();
if (pid == 0) {
printf("pid=%d, ppid=%d, pgid=%d: child=%d\n", getpid(), getppid(), getpgid(getpid()), pid);
pid_t pid = fork();
if (pid == 0) {
printf("pid=%d, ppid=%d, pgid=%d: child=%d\n", getpid(), getppid(), getpgid(getpid()), pid);
pid_t pid = fork();
printf("pid=%d, ppid=%d, pgid=%d\n", getpid(), getppid(), getpgid(getpid()));
sleep(10);
printf("pid=%d, ppid=%d, pgid=%d\n", getpid(), getppid(), getpgid(getpid()));
sleep(10);
} else {
printf("pid=%d, ppid=%d, pgid=%d: child=%d\n", getpid(), getppid(), getpgid(getpid()), pid);
sleep(5);
}
} else {
while (1) {
printf("pid=%d, ppid=%d, pgid=%d: child=%d\n", getpid(), getppid(), getpgid(getpid()), pid);
sleep(20);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment