Last active
October 6, 2015 11:03
-
-
Save vikstrous/151b4c74fc0ab4c10d85 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#define _GNU_SOURCE | |
#include <sched.h> | |
#include <signal.h> | |
#include <errno.h> | |
#include <unistd.h> | |
#include <sys/wait.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <sys/syscall.h> | |
int main() { | |
printf("Cloning...\n"); | |
pid_t pid = syscall(__NR_clone, SIGCHLD | CLONE_NEWPID | CLONE_NEWNET, 0, 0, 0); | |
if (errno != 0) { | |
printf("Cloning failed with errno %d: %s\n", errno, strerror(errno)); | |
return 1; | |
} | |
if (pid != 0) { | |
// Parent: | |
printf("Parent running.\n"); | |
waitpid(pid, 0, 0); | |
printf("Test successful.\n"); | |
return 0; | |
} else { | |
// Child | |
printf("Child running.\n"); | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment