Skip to content
Advertisement

Waiting for system call to finish

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

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?

Advertisement

Answer

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

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

An other alternative could be popen.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement