kill works for processes outside of Perl as well on Win32.

... for a very limited definition of "works". You can use kill to terminate other processes, but you can't send them signals, because Windows doesn't implement signals.

Inside a perl.exe process that pseudo-fork()ed a child-pseudo-process, signals may work, but not outside that process.

Simple example:

killme.pl

#!perl use strict; use warnings; $SIG{'HUP'}=sub { print "Got a HUP signal\n"; }; $SIG{'TERM'}=sub { print "Got a TERM signal\n"; }; open my $f,'>','pid.txt' or die "Could not write pid.txt: $!"; print $f "$$\n"; close $f; $|=1; print "Waiting to be killed\n"; while (1) { print '.'; sleep 30; }

killer.pl:

#!perl use warnings; use strict; open my $f,'<','pid.txt' or die "Start killme.pl first"; my $pid=<$f>; close $f; for my $sig (qw( HUP TERM KILL )) { print "Sending $sig ...\n"; kill($sig,$pid); sleep 2; }

Open two terminals on a Linux system, start both scripts (killme.pl first), and you see this:

tty1tty2
/home/foken>perl killme.pl Waiting to be killed .Got a HUP signal .Got a TERM signal .Killed /home/foken>
/home/foken>perl killer.pl Sending HUP ... Sending TERM ... Sending KILL ... /home/foken>

Open two command shells on Windows, start both scripts (again killme.pl first) and you see this:

Shell 1Shell 2
F:\>perl killme.pl Waiting to be killed . F:\>
F:\>perl killer.pl Sending HUP ... Sending TERM ... Sending KILL ... F:\>

Note that sending HUP terminated killme.pl, completely ignoring the fact that it has set up a HUP signal handler.

One could argue that Windows has no HUP signal, so let's remove the relevant code parts and watch again:

Shell 1Shell 2
F:\>perl killme.pl Waiting to be killed . F:\>
F:\>perl killer.pl Sending TERM ... Sending KILL ... F:\>

Ooops, death by SIGTERM, again ignoring the signal handler inside killme.pl.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^4: TSHARK Child: Windows open2 non-blocking read, or redesign? by afoken
in thread TSHARK Child: Windows open2 non-blocking read, or redesign? by cmv

Title:
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, details, 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, summary, 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.