Re: Monitoring multiple child processes



Taylor, Andrew (ASPIRE) wrote:
OK, I'm clearly being dense here then. My understanding was that the
"$?" contained the status of the pid returned by waidpid.

If waitpid returned a pid from some other process (i.e. not one of my
children) that had failed (i.e return status other than 0) then wouldn't
my test abort the script when it wouldn't need to (as the process that
failed wasn't one of my children) before it got to the redo?

Or have I firmly grasped the wrong end of the stick?

On some systems, waitpid may return something rather than a child pid or
-1. This would happen when the wait was interrupted by something other
than a child death. Most likely, it would be zero.

The return status, $?, is a 16-bit word of three packed values. See
`perldoc perlvar` and search for /\$\?/. It should be set to a non-zero
value by the child if the child does not terminate successfully. Most
UNIX commands do this; most user-written scripts do not. Also, Windows
ignores the return value and always returns zero.

$? should not change unless a child process died.


--
Just my 0.00000002 million dollars worth,
Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.
.



Relevant Pages

  • Re: Killing a process that takes too long
    ... You may instead use fork and exec; this lets you use the process-ID to ... kill 'INT', $pid; ... and it does not guarantee that the child ... So we need a way to kill several processes of the process group of the parent, ...
    (perl.beginners)
  • Re: SBCL just turned 1.0!
    ... Lisp implementation means either lazyness or technical incompetence ... "Return any available status information on child processed. ... (multiple-value-bind (pid status) ... ;; Terminate the child process. ...
    (comp.lang.lisp)
  • Re: OT: fork(): parent or child should run first?
    ... >>> called waitpid() on it? ... > it is actually prepared for the pid to be reclaimed. ... child did some work or slept before it exited. ... > active to an inactive array in the signal handler. ...
    (Linux-Kernel)
  • Re: Killing a process that takes too long
    ... and it does not guarantee that the child ... You can test it by placing $$ (process pid) in the output of these two ... So we need a way to kill several processes of the process group of the parent, ...
    (perl.beginners)
  • Re: optimize log parsing
    ... >> Hey Xho, I tried this: ... >> for the constructor is 0 then, assuming you're in the child process, ... >> called after the successful startup of a child in the parent process. ... >> - pid of the process which has been started ...
    (comp.lang.perl.misc)