0

以下のコードで、子プロセスの作成で問題が発生した場合、または子プロセスに何かが発生した場合はどうなりwait(&status)ますか?

pid_t pid;
int status;
if(pid=fork()){
   printf("Parent Process\n");
   wait(&status);
} else... child process here
4

2 に答える 2

2

If there is a problem creating a child process, fork will return -1, so this code will never wait.

If there's something happend to the child process, wait will return, and you can observe status.

于 2013-09-29T10:27:50.370 に答える
1

If the child cannot be created, fork() will return with -1, you should look at errno after that. No error process is created here. Your code does not check this case.

If the child is created and dies, wait() will return the PID of the terminated process, the reason for the child's death is given in status. See the man page for wait on how to extract meaning from status.

于 2013-09-29T10:27:07.817 に答える