Last active
July 20, 2016 16:25
-
-
Save lstipakov/517b392ab0fb5ab004d440a5688a61ef 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 <stdio.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#include <errno.h> | |
#include <stdlib.h> | |
#define STACK_SIZE 1024*1024 | |
int func(void* param) { | |
printf("I am func, pid %d\n", getpid()); | |
return 0; | |
} | |
int main(int argc, char const *argv[]) { | |
printf("I am main, pid %d\n", getpid()); | |
void* ptr = malloc(STACK_SIZE); | |
printf("I am calling clone\n"); | |
int res = clone(func, ptr + STACK_SIZE, CLONE_VM, NULL); | |
if (res == -1) { | |
printf("clone error: %d", errno); | |
} else { | |
printf("I created child with pid: %d\n", res); | |
} | |
printf("Main done, pid %d\n", getpid()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment