http://www.perlmonks.org?node_id=989603


in reply to Open pipe and fork or system command to retrieve PID and exit status - Best approach?

launch process, retrieve PID, and Exit Status
At the same time? PID belongs to a running process; exit status is an int returned by terminating main(). Unless I've mistaken, you can't have both meaningful at the same time: when you have the exit status, the process is already terminated.
Anyway, have a look at IPC::Run. Other method is to pipe (thus you can read STDOUT), fork (thus you get the PID), exec then waitpid in the main procss (and then use $? to get the exit status).
Sorry if my advice was wrong.

Replies are listed 'Best First'.
Re^2: Open pipe and fork or system command to retrieve PID and exit status - Best approach?
by Anonymous Monk on Aug 24, 2012 at 20:47 UTC

    Sorry, wrong definition from me - I meant Return Status and PID.

    ie. -1 or 0 or 127 etc. and if 0, the PID as well.

    I am really trying to find most suitable approach to fork, and /most reliably/ work with PID obtained, over a period of time, and different script executions. So far I have decided to fork, exec, and in essence use

     do_something() if kill 0, $PID