Previous Thread:   Debugging DLLs

8/27/2005 3:38:53 PM    TcpListener inherited by child processes when UseShellExecute = false
i'm using .NET 2.0, and i've made a lot of tests  
  
i've come to the conclusion that TCP servers (tcplistener), started by  
  
a father process, are somewhat inherited by child processes if using  
  
UseShellExecute = false  
  
why is that ?  
  
try it ! even if the TcpListener is started *after* the  
  
childProcess.Start, the TCP server is still registered in netstat -ao  
  
and connectable with telnet, even if the father process stopped (or  
  
crashed, or was killed)  
  
As long as the child process is living, the TCP server is there, with  
  
the old PID of the father process  
  
When the child process ends, the TCP server disappears and telnet  
  
connection is stopped  
  
This is annoying because it prevent another app from listening on this  
  
port (for example, if you stopped debugging in Visual and you want to  
  
restart debugging your app)  
  
can someone explain this? or is this a bug of .NET 2.0 beta ?  
  
thanks

7250599242


8/28/2005 6:29:03 AM    Re: TcpListener inherited by child processes when UseShellExecute = false
Well,  
  
Under Windows API, you could specify, either through  
  
SECURITY_ATTRIBUTES or through a parameter to CreateProcess if your  
  
child processes would inherit open handles or not.  
  
I haven't find a way to do so under .NET.  
  
I find it a security hole that child process always have access to the  
  
father process' handles.  
  
(and UseShellExecute = true disables some features interesting to the  
  
father process)  
  
I thought *starting* the TcpListener after the child process would be  
  
enough, but I also had to move the TcpListener object creation after  
  
it, in order to solve my problem  
  
Olivier

8/28/2005 1:34:02 PM    Re: TcpListener inherited by child processes when UseShellExecute = false
"Wizou" <Wizou95@gmail.com> wrote in message  
  
news:1125182333.683152.305460@g14g2000cwa.googlegroups.com...  
  
No, it's not a bug, it's by design.  
  
The child process inherits all open handles of the parent process when using  
  
Process.Start, this is the default and cannot be changed.  
  
You can prevent this by starting the child process before you create the  
  
TcpListerner object.  
  
Willy.

8/28/2005 8:22:51 PM    Re: TcpListener inherited by child processes when UseShellExecute = false
Inline  
  
Willy.  
  
"Wizou" <Wizou95@gmail.com> wrote in message  
  
news:1125235743.855582.203690@o13g2000cwo.googlegroups.com...  
  
That's right, it's the CreateProcess API argument bInheritHandles that  
  
specifies whether you want the child to inherit open handles and this is set  
  
to true in .NET, the SECURITY_ATTRIBUTES have nothing to do with this.  
  
If you need this you wil have to call CreateProcess using PInvoke.  
  
What makes you think it's a security hole?  
  
Not sure what features you mean here. >  
  
No, the handle is created with the creation of the TcpClient object.


Search

search