Roll src/third_party/WebKit 75a2fa9:2546356 (svn 202272:202273)
[chromium-blink-merge.git] / docs / linux_pid_namespace_support.md
blob81ce80fb740057bfd17158f328d82ce46c9d00a5
1 # Linux PID Namespace Support
3 The [LinuxSUIDSandbox](linux_suid_sandbox.md) currently relies on support for
4 the `CLONE_NEWPID` flag in Linux's
5 [clone() system call](http://www.kernel.org/doc/man-pages/online/pages/man2/clone.2.html).
6 You can check whether your system supports PID namespaces with the code below,
7 which must be run as root:
9 ```c
10 #define _GNU_SOURCE
11 #include <unistd.h>
12 #include <sched.h>
13 #include <stdio.h>
14 #include <sys/wait.h>
16 #if !defined(CLONE_NEWPID)
17 #define CLONE_NEWPID 0x20000000
18 #endif
20 int worker(void* arg) {
21   const pid_t pid = getpid();
22   if (pid == 1) {
23     printf("PID namespaces are working\n");
24   } else {
25     printf("PID namespaces ARE NOT working. Child pid: %d\n", pid);
26   }
28   return 0;
31 int main() {
32   if (getuid()) {
33     fprintf(stderr, "Must be run as root.\n");
34     return 1;
35   }
37   char stack[8192];
38   const pid_t child = clone(worker, stack + sizeof(stack), CLONE_NEWPID, NULL);
39   if (child == -1) {
40     perror("clone");
41     fprintf(stderr, "Clone failed. PID namespaces ARE NOT supported\n");
42   }
44   waitpid(child, NULL, 0);
46   return 0;
48 ```