wait()
is a system call in Linux system:
int wait(int *status)
Wait for a child to exit; exit status in *status; returns child PID.
int pid = fork();
if(pid > 0){
printf("parent: child=%d\n", pid);
pid = wait((int *) 0);
printf("child %d is done\n", pid);
} else if(pid == 0){
printf("child: exiting\n");
exit(0);
} else {
printf("fork error\n");
}
I feel confused about pid = wait((int *) 0);
,the sign of int wait(int *status)
says it needs a pointer of int,but when calling it bypid = wait((int *) 0)
,is it converting 0
to a pointer,and pid becomes the exact pid of the child? If I am wrong,could anyone pleadse explain what is happening to me?