Fork, processes and exit codes?

Discussion in 'Perl Misc' started by Guest, Feb 3, 2005.

  1. Guest

    Guest Guest

    Hello newsgroup:

    I'm wondering about background processes and OSX.

    I'm using a variant of the fairly standard child reaper:

    sub REAPER {
    my $chld;
    do {
    $chld = waitpid(-1,&WNOHANG);
    if($PROCS{$chld}){
    my($obj) = delete($PROCS{$chld});
    $obj->completed($?);
    }
    } until($chld == -1);
    $SIG{CHLD} = \&REAPER; # Re-install.
    }
    $SIG{CHLD} = \&REAPER;

    Where %PROCS contains a mapping of pid <=> object.

    The $obj->completed($?) method runs a callback function, (typically a bit
    of code to update a status bar that the program terminated with xyz, this
    status message, the ability to track the PID for killing/stopping/etc,
    and backgrounding perl subs, is the whole reason for doing it this way
    instead of system("cmd &"))

    All works so far, but.. if I run programs _after_ a process terminates, in the
    parent process with system(), the error code returned from those programs is
    really messed up:

    $proc->run(\$alert_callback); # Does fork, sets $PROCS{$$} = $obj;
    .....
    .... &$alert_callback is run, indicated process is complete.
    ....
    .... Ok, so now there aren't any background processes running.
    ....
    system("ls");
    ($? >> 8) # Returns 161214215
    # I don't have the actual number handy, but it's a long one.

    I've got $SIG{PIPE} and $SIG{INT} handlers installed for other reasons..
    could this be messsing things up?

    Do I need to do something in &REAPER to call perl's built in CHLD handler,
    if %PROCS doesn't contain my PID?

    --
    http://www.geniegate.com Custom web programming
    (rot13) User Management Solutions
     
    Guest, Feb 3, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vincent Delporte

    "fork and exit" needed?

    Vincent Delporte, Nov 27, 2006, in forum: Python
    Replies:
    14
    Views:
    562
    Vincent Delporte
    Nov 30, 2006
  2. Replies:
    2
    Views:
    2,847
    Malcolm
    Aug 20, 2005
  3. Allen
    Replies:
    1
    Views:
    659
    Mark Rae [MVP]
    Dec 3, 2007
  4. Eric Snow

    os.fork and pty.fork

    Eric Snow, Jan 8, 2009, in forum: Python
    Replies:
    0
    Views:
    575
    Eric Snow
    Jan 8, 2009
  5. Michele Dondi

    A problem with fork() and managing processes

    Michele Dondi, Dec 1, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    133
    Michele Dondi
    Dec 3, 2004
Loading...

Share This Page