Created
November 29, 2016 14:56
-
-
Save lthms/2913377a6d320748fff3de25fb4b5b0c to your computer and use it in GitHub Desktop.
This file contains 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 <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