Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Implementing signals for Win32 Perl using named pipes

by BrowserUk (Patriarch)
on Mar 11, 2008 at 13:50 UTC ( [id://673500]=note: print w/replies, xml ) Need Help??


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.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

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
    That you get these symptoms with PIDs are probably a feature of the way perl is doing things, rather than Windows. PIDs and TIDs are created in the same way by kernel (they are just different flavours of the same thing).

    The pipe will only be destroyed when the last handle is closed. If another process has a handle open then the pipe will not be destroyed when the server dies. However, this does raise a simple solution to my race condition. If the client opens a handle to the server process before opening the pipe then it effectively creates a zombie, so the pid cannot be reused. Obviously tidying these handles will be important.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://673500]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2024-04-23 08:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found