<分区>
我知道 fork()
会创建一个 child ,for loop
会为每个 child 重复 fork()
。但我不知道为什么我得到 7 个子进程重复 3 次。
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
int i;
printf("Process PID %6d \t PPID %6d \n",
getpid(), getppid());
for (i = 0; i<3; ++i)
{
if (fork()==0)
printf("Process PID %6d \t PPID %6d \n", getpid(), getppid());
}
return 0;
}
谁能解释一下这个编码