linux进程fork求教,谢谢
求教,源程序如下(t1.c):
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main()
{
pid_t child = 0;
int i,n;
i = 0;
n = 0;
printf("%d befor %d\n",getpid(),i);
if((child = fork()) <= 0) goto App;
else printf("%d:%d,产生的child进程号为[%d]\n",getpid(),i,child);
App:
printf("mypid is %d,my i is %d,my father is %d,my child is %d\n",getpid(),i,getppid(),child);
return 0;
}
编译命令是:gcc -o 11 t1.c
执行结果为:
7895 befor 0
7895:0,产生的child进程号为[7896]
mypid is 7895,my i is 0,my father is 7409,my child is 7896
7895 befor 0
mypid is 7896,my i is 0,my father is 1,my child is 0
我想问一下,父进程7895产生的子进程7409 goto到App之后,其子进程输出完mypid is 那句话之后不是就退出了吗?
但是为什么7895 befor 0会输出两次呢?谢谢了