Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How to optionally kill a child, and capture status if not killed.

by pc88mxer (Vicar)
on Apr 25, 2008 at 20:48 UTC ( #682916=note: print w/replies, xml ) Need Help??


in reply to How to optionally kill a child, and capture status if not killed.

The value of $? is associated with the last successful waitpid call. In your case things are complicated because you are calling waitpid in two places: your main program and the SIGCHLD handler. I wouldn't be surprised if the SIGCHLD handler is causing $? to get clobbered (with respect to the waitpid call in your main program.)

I would get rid of the SIGCHLD handler, and structure your code to look something like this:

my $script_pid = fork(); ...launch script process... my $abort_pid = fork(); ...launch abort button process.., my $pid = wait; # see who finishes first my $st = $?; # save status if ($pid == $script_pid) { # script finished kill 9, $abort_pid; } else { # assume $pid == $abort_pid, or check it # abort button finished kill 9, $script_pid; }

Replies are listed 'Best First'.
Re^2: How to optionally kill a child, and capture status if not killed.
by joelr (Novice) on Apr 25, 2008 at 21:49 UTC
    Thanks pc88mxer!

    Great tips.

    The key was to wait for either process to finish in the parent, and to use "exec" instead of "system" to not consume the status read by "$?". Before that, I could not get "$?" to reflect the status.

    I will update the example for any future searches.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://682916]
help
Chatterbox?
[erix]: job hunting is an annoying situation to be in. Of course, once settled somewhere you're going to want out again...
[erix]: but that doesn't make the searching less anoying
[Tanktalus]: I've been looking for over 12 months :(

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2017-05-23 19:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?