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
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs