等待系统调用完成
Waiting for system call to finish
我的任务是创建一个程序,该程序接受包含程序列表的文本文件作为输入。然后,它需要在程序上运行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完成?
我想你是在找fork/execv。下面是一个例子:
http://www.cs.ecu.edu/karl/4630/spr01/example1.html可以选择popen
您可以将程序fork
和exec
,然后等待它完成。请看下面的例子:
pid_t pid = vfork();
if(pid == -1)
{
perror("fork() failed");
return -1;
}
else if(pid == 0)
{
char *args[] = {"/bin/sleep", "5", (char *)0};
execv("/bin/sleep", args);
}
int child_status;
int child_pid = wait(&child_status);
printf("Child %u finished with status %dn", child_pid, child_status);
相关文章:
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- 如果整个应用程序是虚拟映射的,为什么 new 会进行系统调用?
- 如何将C++系统调用连接到 freertos
- 如何使用 C/C++ 和 system() 系统调用以外的其他方法在 Linux 中获取文件功能?
- 系统调用:一次和多次,哪个更好?
- 使用路径和空格的系统调用
- 是否有等效于 macOS 上的 clone() 系统调用?
- 从C++调用系统调用节点?
- C++测试程序中的非法系统调用(对角矩阵元素程序的总和)
- 英特尔 Pin:如何获取系统调用的返回地址
- 如何使用低级系统调用从 stdin 和输入文件中获取字节数
- 使用模拟器C++从RISC-V裸机程序调用printf系统调用时失败
- 动态执行的 ARM ASM 系统调用,可从C++重新定位
- 如何知道我正在使用的Linux OS是否具有特定的系统调用
- 当C 中的系统调用conconculables时,参数字符串中的字符损失
- 调用系统调用函数时出现异常
- 在 boost::asio 中自定义套接字/关闭系统调用
- 使用轮询系统调用等待 fds 时 CPU 使用率高
- 等待系统调用完成
- c++等待系统调用