关于父进程先于子进程终止后,子进程应该由init进程收养,所以子进程的ppid不应该是1吗?但我用C语言查看时显示的确是另一个进程id:1795
#include<unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/wait.h>
int main(void)
{
pid_t pid;
if((pid = fork()) == 0)
{
sleep(4);
printf("child 1, pid = %d\tppid = %d\n",pid, getppid());
exit(0);
}
if((pid = fork()) == 0)
{
sleep(3);
printf("child 2, pid = %d\tppid = %d\n",pid, getppid());
exit(0);
}
printf("parent, pid = %d\tppid = %d\n", getpid(), getppid());
exit(0);
}
结果如下:
parent, pid = 5462 ppid = 5305
child 2, pid = 5464 ppid = 1759
child 1, pid = 5463 ppid = 1759
求解释