Re: kill doesn't work correctly

"Octavian Rasnita" <[email protected]>
Newsgroups gmane.comp.lang.perl.active-perl
Message-ID <411B94CCDB994015B9B6581F83E3BFF1@teddy11>
Hi Jan,

I have tried for too many times with wrong results, so I doubt that exactly 
that process ID gets used each time.

But I have tried the following program which always work:

use Win32::Process::Info;

my $pid = 3272;

my @pids = Win32::Process::Info->new->ListPids;

print grep($_ == $pid, @pids) ? 'yes' : 'no';

Thanks.

--
Octavian

----- Original Message ----- 
From: "Jan Dubois" <[email protected]>
To: "'Octavian Rasnita'" <[email protected]>; 
<[email protected]>
Sent: Tuesday, April 06, 2010 1:21 AM
Subject: RE: kill doesn't work correctly


> On Mon, 05 Apr 2010, Octavian Rasnita wrote:
>>
>> C:\Documents and Settings\Octavian>taskkill /pid 1980
>> ERROR: The process "1980" not found.
>> C:\Documents and Settings\Octavian>perl -v
>> This is perl, v5.10.1 built for MSWin32-x86-multi-thread
>> (with 2 registered patches, see perl -V for more detail)
>> C:\Documents and Settings\Octavian>perl -e "print kill(0, 1980);"
>> 1
>>
>> So the process with the PID 1980 doesn't exist, but kill(0) reports that 
>> it exists.
>> Am I doing something wrong or there is a bug in this version of Perl?
>
> I can't reproduce the problem with either build 1006 nor 1007
> (the only 5.10.1 builds of ActivePerl released so far), so I have
> no idea why this is failing for you.
>
> I checked both Windows XP and Windows 7, FWIW.
>
> The only 2 explanations I can come up with are:
>
> 1) The perl process above gets the pid 1980.  Windows reuses pids quite 
> rapidly,
>   so you should print out $$ in your sample script to make sure you are 
> not
>   using this supposedly non-existing pid.
>
> 2) Something else spawns a new process between the time you run 
> taskkill.exe
>   and perl.exe, and that new process gets pid 1980.
>
> kill(0, $pid) on Perl essentially just calls
>
>    handle = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
>
> and if the handle is not NULL then it returns '1', otherwise it returns
> '0'.  I don't see how OpenProcess() could return a valid process handle
> if the PID is not valid at the time of the call.  The OpenProcess
> documentation is here:
>
>    http://msdn.microsoft.com/en-us/library/ms684320%28VS.85%29.aspx
>
> Cheers,
> -Jan
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus 
> signature database 5002 (20100405) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
> 


__________ Information from ESET NOD32 Antivirus, version of virus signature database 5002 (20100405) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.