Guest User

Untitled

a guest
Mar 15th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #define _GNU_SOURCE
  2. #include <unistd.h>
  3. #include <sched.h>
  4. #include <stdio.h>
  5. #include <sys/wait.h>
  6.  
  7. #if !defined(CLONE_NEWPID)
  8. #define CLONE_NEWPID 0x20000000
  9. #endif
  10.  
  11. int worker(void* arg) {
  12. const pid_t pid = getpid();
  13. if (pid == 1) {
  14. printf("PID namespaces are working\n");
  15. } else {
  16. printf("PID namespaces ARE NOT working. Child pid: %d\n", pid);
  17. }
  18.  
  19. return 0;
  20. }
  21.  
  22. int main() {
  23. if (getuid()) {
  24. fprintf(stderr, "Must be run as root.\n");
  25. //return 1;
  26. }
  27.  
  28. char stack[8192];
  29. const pid_t child = clone(worker, stack + sizeof(stack), CLONE_NEWPID, NULL);
  30. //const pid_t child = clone(worker, stack + sizeof(stack), 0x60000000|SIGCHLD, NULL);
  31. if (child == -1) {
  32. perror("clone");
  33. fprintf(stderr, "Clone failed. PID namespaces ARE NOT supported\n");
  34. }
  35.  
  36. waitpid(child, NULL, 0);
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment