in reply to Possible waitpid problem - pid reuse?

Have you thought about using "exec()" instead of "system()" to start whatever process is being run by the child? If the child is doing some setup stuff, running some single command line and exiting, then passing that command line to "exec()" will cause the the child process to be replaced by the exec'ed command. This means that the child's PID gets "taken over" by the exec'ed process, which also means that the PID returned to the parent by "fork" is the only one you need to worry about.

Of course, if anything needs to be done in the child after its sub-process finishes but before the child exits, then you wouldn't want to use "exec()" -- any code located after an "exec()" call is never reached (exec does not return to the caller).

  • Comment on Re: Possible waitpid problem - pid reuse?

Replies are listed 'Best First'.
Re^2: Possible waitpid problem - pid reuse?
by tachyon (Chancellor) on Sep 13, 2004 at 00:53 UTC

    Given that system does a fork, exec and then blocks until the called process completes I don't see what benefit a stright exec would give.

    cheers

    tachyon