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

RE: [PATCH] Fix kill(0, $pid) on Windows

Thread Previous | Thread Next
Jan Dubois
April 17, 2007 09:42
RE: [PATCH] Fix kill(0, $pid) on Windows
Message ID:
On Tue, 17 Apr 2007, Steve Hay wrote:
> Picking a PID that you know exists is easy, but how do you pick a PID
> that you know doesn't exist? PID 0 currently doesn't exist on my
> (WinXP) system, and it probably never does, but I've no idea how
> portable that might be.

PID 0 is used by the "System Idle Process".  It is also used under POSIX
to indicate the current process group:

Note that with the current implementation of kill() and killpg() we can
only kill() processes that are running under the same uid as the perl
process itself. This limitation also applies to kill(0, $pid), so even
though pid 0 may exist, you don't see it because it is owned by the
system account.

This limitation is true even when you are running with Administrator
rights. We can fix this by trying to acquire the SeDebugPrivilege
privilege for the current perl process. I just didn't want to have this
privilege turned on permanently. I'll try to come up with a patch that
just turns it on for the OpenProcess() call and then turns it off again.

As for finding a non-existing PID, I was thinking about just running it
over a huge list of integers (1..30_000) and see if *all* the processes
seem to exist, which seems rather unlikely.  Anyways, that test would
have caught the specific failure I fixed with this patch.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About