在看APUE时,照8-8例敲了如下代码
#include"apue.h"
#include<error.c>
#include <sys/wait.h>
int main(void)
{
pid_t pid;
if((pid = fork()) < 0)
err_sys("fork error");
else if(pid == 0)
{
if((pid= fork()) < 0)
err_sys("fork error");
else if(pid > 0)
exit(0);
sleep(4);
printf("second child, parent pid = %ld\n",(long)getppid());
exit(0);
}
if(waitpid(pid, NULL, 0) != pid)
err_sys("waitpid error");
exit(0);
}
输出second child, parent pid = 2372
按理说,第一个子进程结束,第二个子进程的父进程应该是init进程,pid = 1,
为啥我这个总是等于2372呢