Skip to content

Instantly share code, notes, and snippets.

@bongbongco
Created December 18, 2016 13:19
Show Gist options
  • Save bongbongco/4f2b24cc82ca23643c4d1cf0bff79f0d to your computer and use it in GitHub Desktop.
Save bongbongco/4f2b24cc82ca23643c4d1cf0bff79f0d to your computer and use it in GitHub Desktop.
vfork - 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 vfork \n \n");
if((pid=vfork()) < 0 ) {
perror("fork error \n");
exit(-2);
} else if (pid == 0) {
printf("TGID(%d), PID(%d) : Child \n", getpid(), syscall(__NR_gettid));
_exit(0);
} else {
printf("TGID(%d), PID(%d) : Parent \n", getpid(), syscall(__NR_gettid));
}
printf("after vfork \n \n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment