我想使用指针来获取父进程的pid及其子进程:
int main(void){
pid_t childPid,*parentPid,pid;
childPid = fork();
if(childPid == 0 ){
printf("[Child] the parent pid is 0x%u\n", *parentPid);
}else if(childPid < 0){
printf("there is something wrong");
}else{
pid = getpid();
printf("[Parent] the pid is 0x%u\n",pid);
parentPid = &pid;
}
return (EXIT_SUCCESS);
}
输出是:
[Parent] the pid is 0x5756
[Child] the parent pid is 0x1
我的代码一定有问题,知道吗?