Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I have a multithreaded application which spawns threads to track work. The single parent thread creates all the children threads. Each child thread executes an external command and then captures the output via an open on a pipe. If the child thread doesn't complete within some time limit, the parent sends the child a signal, and the child in turn attempts to kill the external process.

I'm not sure if its the fact that its windows and emulated, or if its due to some rule regarding waiting on I/O, but the child thread doesn't appear to be acting immediately on the signals. When I interupt the parent, then the child thread suddenly reports the earlier signals.

I don't want to SIGKILL the child thread as I want it to report what it had accomplished to that point. However, I set it up so that if I sent it a NUM16, it would do a SIGKILL on the external command. Since this didn't have any effect, it appears that its the child thread that is not responding, not the external command.

Maybe there's a totally better way of doing this.... Following is a snippet of the child thread code.

$self->msg('execute', dir => Cwd::getcwd(), cmd => $self->{cmd}, 'eval +' => $cmd); my $pid = open EXEC, "-|", "($cmd)2>&1" or die "Could not start comman +d."; foreach ( qw{ ABRT ALRM BREAK FPE HUP ILL INT PIPE QUIT SEGV STOP TERM + } ) { $SIG{$_} = sub { warn "$self->{-full}: Signal $_ caught"; $self->msg +('signal', signal => $_[0]); kill $_[0], $pid; }; } foreach ( qw{ USR1 NUM16 } ) { $SIG{$_} = sub { warn "$self->{-full}: Signal $_ caught"; $self->msg +('signal', signal => 'KILL'); kill 'KILL', $pid; }; } while (<EXEC>) { chomp; $self->msg('execute', output => $_); } close EXEC; $self->set(status => $?, stop => Scheduler::Time::utc); foreach ( qw{ ABRT ALRM BREAK FPE HUP ILL INT PIPE QUIT SEGV STOP TERM + USR1 NUM16 } ) { $SIG{$_} = 'DEFAULT'; };

In reply to Signals vs. Windows by DanEllison

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-23 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found