in reply to Re^2: How do I cleanly kill a spawned process on Win32.
in thread How do I cleanly kill a spawned process on Win32.
The program does not need to call SetConsoleCtrlHandler() if the only concern is shutdown via DllMain.
If you are going to allow the default handler to call ExitProcess(), then I see no advantage over calling TerminateProcess(). You wouldn't even be able to choose what exit value is returned.
If the OP is hoping to be able to perform some kind of clean up and controlled shutdown, he would need to install his own handler.
The idea way would be to have a thread of the server waiting on an Event, then fire the Event when closedown is needed.
You'd have to expand on that a little. What would be the advantage in having a separate thread?
SetConsoleCtrlHandler() can already handle all of these events:
Are you suggesting that the OP should spawn a separate thread that installs handlers and then goes to sleep waiting for them to occur? If so, how would you suggest that it then "interupt" the main thread when they do?
Or are you suggesting creating some kind of user event that this extra thread would wait on? If so, how would the Perl script generate that event? And what would the extra thread do with it when it arrived?
|
|---|