Skip to content

Instantly share code, notes, and snippets.

@bongbongco
Last active December 18, 2016 13:19
Show Gist options
  • Save bongbongco/cf0e77f76b6fdc5c28e930717ccfa73d to your computer and use it in GitHub Desktop.
Save bongbongco/cf0e77f76b6fdc5c28e930717ccfa73d to your computer and use it in GitHub Desktop.
fork - TGID, PID
#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