Re: socket in LISTENING state after a call to closesocket

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



The socket is release when I kill the subprocess. I have used
calc.exe as subprocess with the same behavior.

What was your question? It sounds as if subprocesses are being
created with the "inherit handles" capability enabled. Until the
subprocess closes its handle, the socket isn't really closed. Or
something like that.

My question was why the socket was still in LISTENING mode after I
called closesocket but your answer raised another question. "inherit
handles" capability, how does it work and how do I turn it off on a
process started from managed code.

You can't, because it's not an attribute of the process. It's controlled at
the time the child process is launched.

In Windows, all methods of starting a process eventually call CreateProcess
http://msdn.microsoft.com/en-us/library/ms682425(loband).aspx

Apparently Process.Start or whatever you are using to start a child task is
passing TRUE as the value of bInheritHandles. And if the framework is
starting a child task somewhere, somehow, and allowing it to inherit
handles.... then you're pretty much at its mercy. But I would be surprised
to find out that the framework is doing something so stupid. More likely
it's a global Windows hook or other injected DLL (things like multi-monitor
management programs often install these) that is making unauthorized
duplicates of your handle.


.



Relevant Pages

  • Re: subprocess.Popen inheriting
    ... File descriptors are not, they exist only to please the C runtime library. ... A subprocess may inherit handles from its parent. ... "Anonymous" pipes are good to replace stdin/stdout/stderr, because there is no need to explicitely communicate the handle value to the subprocess: one just replaces the corresponding handle with the desired pipe, and the subprocess might not even notice it. ...
    (comp.lang.python)
  • Re: socket in LISTENING state after a call to closesocket
    ... created with the "inherit handles" capability enabled. ... subprocess closes its handle, ... My question was why the socket was still in LISTENING mode after I ... Apparently Process.Start or whatever you are using to start a child task is passing TRUE as the value of bInheritHandles. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Adding a library to @INC
    ... Should do the trick. ... If it is actually the Oracle client then you might ... try the same because *theoretically* the subprocess should inherit and ...
    (perl.beginners)
  • [RFC][PATCH 15/19] perf: Move some code around
    ... Move all inherit code near each other. ... * inherit a event from parent task to child task: ... -static struct perf_event * ...
    (Linux-Kernel)