当我运行下面的代码
#include <stdio.h>
#include <sys/types.h>
//int i=0;
int main(){
int id ;
id = fork() ;
printf("id value : %d\n",id);
if ( id == 0 )
{
printf ( "Child : Hello I am the child process\n");
printf ( "Child : Child’s PID: %d\n", getpid());
printf ( "Child : Parent’s PID: %d\n", getppid());
}
else
{
printf ( "Parent : Hello I am the parent process\n" ) ;
printf ( "Parent : Parent’s PID: %d\n", getpid());
printf ( "Parent : Child’s PID: %d\n", id);
}
}
我的输出
id value : 20173
Parent : Hello I am the parent process
Parent : Parent’s PID: 20172
Parent : Child’s PID: 20173
id value : 0
Child : Hello I am the child process
Child : Child’s PID: 20173
Child : Parent’s PID: 1
如何能在父母的PID(20172)从孩子的父母的ID(1)有什么区别? 如果不是这两个相等?