[Israel.pm] Exit code and pid in one.

Shlomi Fish shlomif at iglu.org.il
Tue Jun 15 03:22:46 PDT 2004


On Tuesday 15 June 2004 11:52, Tal Kelrich wrote:
> On Tue, 15 Jun 2004 11:07:23 +0300
>
> Thomas Maier <hayzer at 012.net.il> wrote:
> > Hi All,
> > If I spawn a process from perl, and I need both its PID and the return
> >
> > value, is there a straight-forward way (no fork involved)?
> > system gets the exit code, open ___|-___ returns the PID.
> > How can I get them both at once?
> > Thanks ahead,
> > Thomas.
>
> I would try using waitpid to get the status.

Well, for such operations perl manages its own wait() and waitpid() policy. If 
you try to use waitpid() here yourself, you may interfere with it, create 
zombies, etc.

A better idea may be to use the $? (or $CHILD_ERROR in English) special 
variable. Read about it in perldoc perlvar. Note that I did not try to see if 
it works with open "|-".

Regards,

	Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish      shlomif at iglu.org.il
Homepage:        http://shlomif.il.eu.org/

Quidquid latine dictum sit, altum viditur.
        [Whatever is said in Latin sounds profound.]



More information about the Perl mailing list