如果子调用exec,wait()会做什么?
What does wait() do if the child calls exec?
如果子进程调用 exec,它将终止并使用相同的 pid 创建一个新进程。
wait() 函数会等待子进程或孙进程终止吗?
If a child calls exec it terminates and a new process is created with the same pid.
不,不完全是。
exec
不会创建新进程——它会用新程序覆盖单个进程(旧进程)。所以没有新的child(没有"grandchild"),也没有新的pid。因此,如果 parent 调用 wait
,它不会 return,直到 exec
的程序调用。 (事实上,exec
没有太多外部影响,parent 根本无法检测到。)
如果子进程调用 exec,它将终止并使用相同的 pid 创建一个新进程。
wait() 函数会等待子进程或孙进程终止吗?
If a child calls exec it terminates and a new process is created with the same pid.
不,不完全是。
exec
不会创建新进程——它会用新程序覆盖单个进程(旧进程)。所以没有新的child(没有"grandchild"),也没有新的pid。因此,如果 parent 调用 wait
,它不会 return,直到 exec
的程序调用。 (事实上,exec
没有太多外部影响,parent 根本无法检测到。)