std::system, are these children? [Archive] - C Board

PDA

View Full Version : std::system, are these children?


m3the01
03-12-2008, 04:29 PM
Could someone point me to the correct documentation?
I attempted waiting on -1, which waits for a child to exit.

But they dont seem to be children.

std::system("./satSolver1 SATTest.txt >results1.txt &");
std::system("./satSolver2 SATTest2.txt >results.txt &");

Then i would like to wait for the first one to finish

Thanks for the help

brewbuck
03-12-2008, 04:56 PM
Could someone point me to the correct documentation?
I attempted waiting on -1, which waits for a child to exit.

But they dont seem to be children.

You're right, they aren't. std::system() launches a shell with the command line you give it. The command line includes '&', which puts the process in the background -- in other words, forks it off and closes its standard descriptors. Then the shell dutifully exits, causing the children to be re-parented all the way back to init. You are not the parent of these processes and have no control over them because you have no way of getting the PID.

You can't use std::system() to achieve what you want. You will need to fork() and then exec().

m3the01
03-13-2008, 01:37 PM
appreciate the help and the suggestion.

Thanks!

m3the01
03-13-2008, 03:21 PM
So could u give me a quick code snap of using exec? Never used it,

Thanks

m3the01
03-13-2008, 04:09 PM
hmm i got execl working but one problem, i now dont have the exit value. Anyway to get the exit value?

brewbuck
03-13-2008, 04:20 PM
hmm i got execl working but one problem, i now dont have the exit value. Anyway to get the exit value?

You have to call wait() on the PID.

m3the01
03-17-2008, 09:06 AM
yeah found the wexitstatus(status) call,

Thanks again