Last active
December 18, 2016 15:06
-
-
Save bongbongco/99b83daf88364a458ea7e057dde58083 to your computer and use it in GitHub Desktop.
clone TGID, PID
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
#include <sys/types.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <linux/unistd.h> | |
#define _GNU_SOURCE | |
#include <linux/sched.h> | |
void sub_func(void *arg) | |
{ | |
printf("TGID(%d), PID(%d) : Child \n", getpid(), syscall(__NR_gettid)); | |
sleep(2); | |
return 0; | |
} | |
int main(void) | |
{ | |
int pid; | |
int child_a_stack[4096], child_b_stack[4096]; | |
printf("before clone \n \n"); | |
printf("TGID(%d), PID(%d) : Parent \n", getpid(), syscall(__NR_gettid)); | |
clone(sub_func, (void *)(child_a_stack+4095), CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID, NULL); | |
clone(sub_func, (void *)(child_b_stack+4095), CLONE_VM | CLONE_THREAD | CLONE_SIGHAND, NULL); | |
sleep(1); | |
printf("after clone \n \n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment