Jon Davis said:
[...]
Windows does not have "child processes", each process is independent. There
is no direct correlation, to my knowledge, of interacting two processes that
both utilize TCP/IP, except using Windows API calls or else opening a TCP/IP
socket on another application port and communicating "over the wire". You
can, of course, indirectly query the stack to see if another application is
bound to a specific port, such as by attempting to bind to the port and
handling any exceptions that occur in that attempt.
Really? I had gathered that Windows didn't have a "process tree"
parent/child relationship like UNIX systems do, but I could swear that I
came across references to windows apps sharing open files and network
connections that way. But I have to admit, given .NET semantics, I couldn't
figure out how it'd be done.
[...]
You should never kill a TCP/IP port-bound application's process abruptly.
Request a closure. If it is a Windows Service, handle the Stop event [or
equivalent]. Then, while closing or stopping, the process should stop the
TcpListener.
I do do that. The chain of events is something like the following. And,
just to be clear, the two services are actually the same service. Just
different instantiations of it.
Old myService KillerProg New myService
------------ ---------- ----------
---
Gets Start Event
Creates TcpListener
Gets "restart" msg
Spawns KillerProg
Invokes "net stop
myService"
Waits for that to
finish
Gets Stop Event
Closes TcpListener
Exits
Sleeps 2 seconds
Invokes "net start
myService"
Waits for that to
finish
Gets Start Event
Creates TcpListener
Exits
and at this point, clients cannot connect to the new TcpListener, though,
oddly, I didn't get a failure from the second TcpListener creation. And,
like I said, if I invoke KillerApp from a cmd.exe shell (as opposed to
having myService invoke it itself), it works just fine. So it would seem
that it has something to do with how the first myService shutsdown when it
has spawned this process.
As an experiment, I added a call to close the TcpListener to myService right
before it invokes KillerApp. This seemed to solve the problem (again, very
similar to what would happen in POSIX had I not set it to closeOnExec).
Unfortunately, I can't leave it this way since I don't know whether
KillerApp is really going to restart the services (it's not really
KillerApp, it's more like "HelperApp", which sometimes turns out to restart
the services). So it really does seem that something about spawning off
the KillerApp before I close the TcpListener keeps it from dying correctly
when stopped by a process that it itself spawned.
Hrm....
Thanks,
Doug
[...]
HIR [Hope I'm Right],
Jon
[...]