Skip to content

Instantly share code, notes, and snippets.

@vikstrous
Last active October 6, 2015 11:03
Show Gist options
  • Save vikstrous/151b4c74fc0ab4c10d85 to your computer and use it in GitHub Desktop.
Save vikstrous/151b4c74fc0ab4c10d85 to your computer and use it in GitHub Desktop.
#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