我有以下程序
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
main()
{
pid_t pid, ppid;
printf("Hello World1\n");
pid=fork();
if(pid==0)
{
printf("I am the child\n");
printf("The PID of child is %d\n",getpid());
printf("The PID of parent of child is %d\n",getppid());
}
else
{
while(1)
{
printf("I am the parent\n");
printf("The PID of parent is %d\n",getpid());
printf("The PID of parent of parent is %d\n",getppid());
}
}
}
这个程序的输出是父进程永远运行而不切换到子进程。在这种情况下,为什么没有切换到子进程?