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

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

Thread Previous | Thread Next
From:
Steve Hay
Date:
April 17, 2007 10:11
Subject:
Re: [PATCH] Fix kill(0, $pid) on Windows
Message ID:
4624FF9B.5040107@uk.radan.com
Jan Dubois wrote:
> 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".  

Doh! Yes, I see it in my Task manager now. I wonder why I didn't notice 
it before. Not enough coffee, obviously.


> It is also used under POSIX
> to indicate the current process group:
> 
>     http://www.opengroup.org/onlinepubs/009695399/functions/kill.html
> 
> 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.

That would be useful. It would at least have saved me kidding myself 
that there wasn't a PID 0 when there is!


> 
> 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.

The attached works OK for me (and fails OK if I revert your fix). Is 
this all right now?

-- 

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