Skip to content

Instantly share code, notes, and snippets.

@lthms
Created November 29, 2016 14:56
Show Gist options
  • Save lthms/2913377a6d320748fff3de25fb4b5b0c to your computer and use it in GitHub Desktop.
Save lthms/2913377a6d320748fff3de25fb4b5b0c to your computer and use it in GitHub Desktop.
#define _GNU_SOURCE
#include <sched.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#define STACK_SIZE 0x20000
int fn (void *data) {
printf("child: %d\n", getpid());
char *cmd[] = { "/bin/sh", NULL };
execv(cmd[0], cmd);
return 1;
}
int main (void) {
void *stack = malloc (STACK_SIZE);
int test = clone(fn, stack + STACK_SIZE, CLONE_NEWNS|CLONE_NEWPID, NULL);
printf("test %d\n", test);
waitpid(-1, NULL, __WALL);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment