fork 一個 孤兒進程
fork 以后 父進程和子進程 pid 不一樣,其中子進程已經成為孤兒進程。可以參考下面兩個鏈接了解。
https://www.cnblogs.com/chilumanxi/p/5136102.html
https://www.cnblogs.com/chilumanxi/p/5136102.html
#include <stdio.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> int main(int argc,char *argv[]){ pid_t pid; pid = fork(); if(pid == 0) { printf("Here is child,my pid = %d,my parent pid = %d\r\n",getpid(),getppid()); exit(0); }else if(pid > 0) { printf("here is parent,my pid = %d,child's pid = %d\n",getpid(),pid); }else{ perror("fork error\n"); } return 0; }
*博客內容為網友個人發布,僅代表博主個人觀點,如有侵權請聯系工作人員刪除。