1# Linux PID Namespace Support
2
3The [LinuxSUIDSandbox](suid_sandbox.md) currently relies on support for
4the `CLONE_NEWPID` flag in Linux's
5[clone() system call](http://www.kernel.org/doc/man-pages/online/pages/man2/clone.2.html).
6You can check whether your system supports PID namespaces with the code below,
7which must be run as root:
8
9```c
10#define _GNU_SOURCE
11#include <unistd.h>
12#include <sched.h>
13#include <stdio.h>
14#include <sys/wait.h>
15
16#if !defined(CLONE_NEWPID)
17#define CLONE_NEWPID 0x20000000
18#endif
19
20int 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  }
27
28  return 0;
29}
30
31int main() {
32  if (getuid()) {
33    fprintf(stderr, "Must be run as root.\n");
34    return 1;
35  }
36
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  }
43
44  waitpid(child, NULL, 0);
45
46  return 0;
47}
48```
49