win32 - kill 0 and handle leaks.

W

W K

I have a process that needs to check pids of other processes on win2000.

However, whenever when I do a kill 0, $pid - the number of handles (seen in
task manager) goes up by one.

As the process does this every minute non-stop, this gets to be a large
number of processes.

Is this a known bug/feature/mistake? Is there anything I should be doing to
clean up these handles?



The following replicates the problem - note that the "3004" must be a
process that is currently running.

for (1..5){

sleep 2;

for (1..100){kill 0,3004 }

}

print "press return";$_=<STDIN>;
 
S

Sisyphus

W K said:
I have a process that needs to check pids of other processes on win2000.

However, whenever when I do a kill 0, $pid - the number of handles (seen in
task manager) goes up by one.

As the process does this every minute non-stop, this gets to be a large
number of processes.

Is this a known bug/feature/mistake? Is there anything I should be doing to
clean up these handles?



The following replicates the problem - note that the "3004" must be a
process that is currently running.

for (1..5){

sleep 2;

for (1..100){kill 0,3004 }

}

print "press return";$_=<STDIN>;

Afaict, you're doing nothing wrong - and when I run your script I see
precisely what you're seeing (with both perl 5.6.1 and 5.8.0).

I can't find any documentation warning of this behaviour and I can't find
any way of clearing those handles without having the script exit.

(Just stop and re-start the checking process
every-so-often :)

Alternatively you can probably achieve what you're after with one of the
Win32 modules. Win32::perfLib ( http://www.bybyte.de/jmk/Perl5.asp ) should
accommodate your needs, or Win32::process::Info (from cpan) might also do
it.

Cheers,
Rob
 
W

W K

Afaict, you're doing nothing wrong - and when I run your script I see
precisely what you're seeing (with both perl 5.6.1 and 5.8.0).

I can't find any documentation warning of this behaviour and I can't find
any way of clearing those handles without having the script exit.

Thank you. I'm not insane then.
(Just stop and re-start the checking process
every-so-often :)

well, I'd got 50 day's worth at 4/minute.
Alternatively you can probably achieve what you're after with one of the
Win32 modules. Win32::perfLib ( http://www.bybyte.de/jmk/Perl5.asp ) should
accommodate your needs, or Win32::process::Info (from cpan) might also do
it.

Yes, I have gone for the latter can get a list of pids, which fits much the
same purpose as testing with "kill 0".
Of course, it can also tell you much more about the processes so should be
more useful, should I chose to extend the functionality.
 
D

Daniel Berger

W K said:
Thank you. I'm not insane then.

Nope, you've found a bug in win32.c. It appears that when returning a
value from signal 0 (or 2) a CloseHandle() call was omitted. Since
this is only noticable when calling kill in a loop, no one noticed
until now. :)

I've submitted a bug report to perl5porters and it will (hopefully) be
patched for 5.8.1.

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,121
Messages
2,570,712
Members
47,283
Latest member
hopkins1988

Latest Threads

Top