in reply to Re: Implementing signals for Win32 Perl using named pipes
in thread Implementing signals for Win32 Perl using named pipes
PIDs can get reused at once on Windows.
Really? On my system I cannot get a pid to be reused with anything less that 2632 intervening process starts. Indeed, it is always 2632 intervening starts on my system, which maybe indicative of some flaw in my test method. But still, I think the quoted statement is suspect also?
#! perl -slw use strict; my %pids; for ( 1 .. 2**16 ) { print my $p = open my $cmd, "cmd /c echo $_ |"; 1 while <$cmd>; close $cmd; exists $pids{ $p } and die sprintf "Duplicate $p after %d process starts", keys % +pids; $pids{ $p }++; } __END__ Duplicate 3904 after 2632 process starts at C:\test\junk11.pl line 10.
Using a TID rather than a PID may resolve them, and make the race condition less likely, but still not impossible.
Thread ids are simple incrementing numbers starting from 1 in each process, and would be more (very) likely to be repeated.
I'm not at all certain that there is a potential race condition. If the process with the pid creates its own named pipe, then when the process terminates for any reason, that named pipe will cease to exist before the process is finally cleared from memory. The system won't allow that to happen until all open handles have been destroyed. And it won't allow the reuse of a pid until the old process has been properly cleaned from the internal tables.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Implementing signals for Win32 Perl using named pipes
by cdarke (Prior) on Mar 12, 2008 at 10:16 UTC |