本文介绍了在主等待execvp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
INT的main()
{
...
如果(!叉())
{
execvp(cmdName,cmdParam);
}
的printf(在main()......);
返回(0);
}
- 假设我已经正确地通过了cmdName&放大器; cmdParam争论,我怎么等待由execvp创建的过程完成,恢复的main()? 执行前
- 请问execvp()创建一个过程,是新fork()的编辑过程中的孩子?
解决方案
-
在父进程,
叉
返回子进程的PID,这样你就可以存储在一个变量,然后使用waitpid函数
来等待子进程终止。 -
不是真的 - 通过创建新的子进程
叉
是父的副本,而execvp
然后用一个新形象替换其处理图像。有效地最初有父母的两个拷贝,然后一变成了新的方案。
int main()
{
...
if(!fork())
{
execvp(cmdName,cmdParam);
}
printf("In main()...");
return(0);
}
- Assuming I have correctly passed the cmdName & cmdParam arguments, how do I wait for the process created by execvp to finish, before resuming the execution of main()?
- Does the execvp() create a process which is a child of the newly fork()ed process?
解决方案
In the parent process,
fork
returns the PID of the child process, so you can store that in a variable, and then usewaitpid
to wait for the child process to terminate.Not really - the new child process created by
fork
is a duplicate of the parent, andexecvp
then replaces its process image with a new image. Effectively you initially have two 'copies' of the parent, one of which then 'becomes' the new program.
这篇关于在主等待execvp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!