等待系统调用完成 [英] Waiting for system call to finish

查看:41
本文介绍了等待系统调用完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been tasked to create a program that takes a text file that contains a list of programs as input. It then needs to run valgrind on the programs (one at a time) until valgrind ends or until the program hits a max allotted time. I have the program doing everything I need it to do EXCEPT it isn't waiting for valgrind to finish. The code I'm using has this format:

//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 完成?

I'm running into an issue where the child just calls the system and moves on without waiting for valgrind to finish. As such I'm guessing that system isn't the right call to use, but I don't know what call I should be making. Can anyone tell me how to get the child to wait for valgrind to finish?

推荐答案

我认为您正在寻找 fork/execv.下面是一个例子:

I think that you are looking for fork/execv. Here is an example:

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

另一种选择可能是 popen.

An other alternative could be popen.

这篇关于等待系统调用完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆