#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
int main(int argc,char *argv[])
{
int i;
for(i=0; i<3; i++)
{
pid_t pid = fork();
if(pid == 0)
{
break;//子进程退出for循环,也就没有机会执行fork()了。
printf("child is pid ==%d,my parent is pid==%d\n",getpid(),getppid());
}else if(pid>0)
{
printf("--parent process--pid:%d,my pid:%d,my parent is pid==%d\n",pid,getpid(),getppid());
}
sleep(1);
}
return 0;
}
05-21
05-21
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交