fork() 系统调用可以创建进程。然后查看进程ID和父进程ID使用getpid()和getppid()函数.
使用C语言描述:
#include#include int main (int argc, char *argv[]){ pid_t child = -1; if ((child = fork()) == 0) { fprintf(stderr, "1: child pid is %u\n", getpid()); fprintf(stderr, "2: his parent is %u\n", getppid()); } else { fprintf(stderr, "3: parent pid is %u\n", getpid()); } return 0;}
运行结果: