gpt4 book ai didi

c++ - 等待系统调用完成

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:51:47 26 4
gpt4 key购买 nike

我的任务是创建一个程序,该程序将包含程序列表的文本文件作为输入。然后它需要在程序上运行 valgrind(一次一个)直到 valgrind 结束或直到程序达到最大分配时间。我让程序做我需要它做的一切,除了它不等待 valgrind 完成。我使用的代码格式如下:

//code up to this point is working properly
pid_t pid = fork();
if(pid == 0){
string s = "sudo valgrind --*options omitted*" + testPath + " &>" + outPath;
system(s.c_str());
exit(0);
}
//code after here seems to also be working properly

我遇到了一个问题, child 只是调用系统并继续前进,而没有等待 valgrind 完成。因此,我猜测该系统不适合使用,但我不知道我应该调用什么电话。谁能告诉我如何让 child 等待 valgrind 完成?

最佳答案

我认为您正在寻找 fork/execv。这是一个例子:

http://www.cs.ecu.edu/karl/4630/spr01/example1.html

可以打开另一个替代方案。

关于c++ - 等待系统调用完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30623063/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com