Created
November 18, 2021 14:46
-
-
Save sitano/cf54d94ae6286f97158d3fad9d032939 to your computer and use it in GitHub Desktop.
test reaping caps
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 <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