Last active
December 18, 2016 13:19
-
-
Save bongbongco/cf0e77f76b6fdc5c28e930717ccfa73d to your computer and use it in GitHub Desktop.
fork - TGID, PID
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
#include <sys/types.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <linux/unistd.h> | |
int main(void) | |
{ | |
int pid; | |
printf("before fork \n \n"); | |
if((pid=fork()) < 0 ) { | |
perror("fork error"); | |
exit(-2); | |
} else if (pid == 0) { | |
printf("TGID(%d), PID(%d) : Child \n", getpid(), syscall(__NR_gettid)); | |
} else { | |
printf("TGID(%d), PID(%d) : Parent \n", getpid(), syscall(__NR_gettid)); | |
sleep(2); | |
} | |
printf("after fork \n \n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment