std::system, are these children?

This is a discussion on std::system, are these children? within the Linux Programming forums, part of the Platform Specific Boards category; Could someone point me to the correct documentation? I attempted waiting on -1, which waits for a child to exit. ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    5

    std::system, are these children?

    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
    Last edited by m3the01; 03-12-2008 at 04:37 PM.

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Quote Originally Posted by m3the01 View Post
    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().

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    5
    appreciate the help and the suggestion.

    Thanks!

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    5
    So could u give me a quick code snap of using exec? Never used it,

    Thanks

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    5
    hmm i got execl working but one problem, i now dont have the exit value. Anyway to get the exit value?

  6. #6
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Quote Originally Posted by m3the01 View Post
    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.

  7. #7
    Registered User
    Join Date
    Mar 2008
    Posts
    5
    yeah found the wexitstatus(status) call,

    Thanks again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MDI children always maximized?
    By Devils Child in forum Windows Programming
    Replies: 4
    Last Post: 02-25-2009, 06:43 AM
  2. Linux Putting my children to sleep with futex!?
    By Abs in forum Linux Programming
    Replies: 18
    Last Post: 02-12-2009, 05:43 PM
  3. forks and children
    By suigeneris in forum C Programming
    Replies: 1
    Last Post: 01-22-2005, 04:48 AM
  4. "Which parent has children with no children"?!?
    By SMurf in forum C Programming
    Replies: 2
    Last Post: 04-28-2003, 01:59 PM
  5. Training children to commit suicide.
    By Liger86 in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 02-06-2003, 08:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21