Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

comment on

( #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

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (3)
    As of 2021-01-21 08:23 GMT
    Find Nodes?
      Voting Booth?