【发布时间】:2015-08-17 20:07:09
【问题描述】:
我的任务是创建一个程序,该程序接受一个包含程序列表的文本文件作为输入。然后它需要在程序上运行 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
我遇到了一个问题,孩子只是调用系统并继续前进,而无需等待 valgrind 完成。因此,我猜测系统不是正确的调用,但我不知道我应该打什么电话。谁能告诉我如何让孩子等待 valgrind 完成?
【问题讨论】: