#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main (int argc, char * argv[]) {
printf("I am parent! My id: %d\n", (int)getpid());
pid_t childPIDorZero = fork();
if (childPIDorZero == -1) {
perror("fork() error");
exit(-1);
}
if (childPIDorZero == 0) {
printf("Success. ID: %d, Parent ID: %d\n", (int)getpid(), (int)getppid());
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
1结果:
2结果:
我不明白这个故事.结果1为true但结果2为false但我没有做任何更改.为什么父ID结果不同?