develooper Front page | perl.perl5.porters | Postings from April 2007

killpg() on Windows

Thread Previous | Thread Next
From:
Jan Dubois
Date:
April 18, 2007 14:42
Subject:
killpg() on Windows
Message ID:
00ec01c78202$4aafa900$e00efb00$@com
[was: Re: [PATCH] Fix kill(0, $pid) on Windows]

On Wed, 18 Apr 2007, Steve Hay wrote:
> Also, kill(9, $pid) kills another perl.exe process OK, but
> 
> perl -le "kill 9, undef; print 'Hi'"
> 
> doesn't kill the current perl process: the program prints 'Hi' and exits
> normally. Same with kill(9, 0) in place of kill(9, undef).

During this discussion I realized that my implementation of killpg()
for Windows works quite differently from the POSIX definition.

My implementation is essentially a "signal process tree", following
process parent/child relations.

The POSIX killpg() signals all processes in a process group, and you
really need to specify a $pgid (which happens to be the same number as
the $pid of the process group leader).  There isn't really a way to signal
all processes in a process tree under POSIX (AFAICT).  The closest you
can get is by calling POSIX::setpgid() after fork(), but before exec()
in all your child processes to assign them all to a separate process
group.  Processes can still break away by assigning themselves to
a different process group.

The closest thing to process groups on Windows are probably the
Job objects introduced in Windows 2000 (somewhat accessible from
Perl via the Win32::Job module).

I wonder where this leaves us with the kill(-$ig, $pid) implementation
on Windows?  Should the different semantics just be documented
(because killing/signaling a process tree seems useful)?  Or should
that functionality be moved to a separate module?

Cheers,
-Jan


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About