等待系统调用完成

编程入门 行业动态 更新时间:2024-10-24 05:22:41
本文介绍了等待系统调用完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我的任务是创建一个程序,该程序将包含程序列表的文本文件作为输入.然后它需要在程序上运行 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-28 07:32:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1169700.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:系统

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!