Run arbitrary subprocesses on Windows and still terminate cleanly?
Posted
by Weeble
on Stack Overflow
See other posts from Stack Overflow
or by Weeble
Published on 2009-09-21T09:01:30Z
Indexed on
2010/03/12
8:17 UTC
Read the original article
Hit count: 253
I have an application A that I would like to be able to invoke arbitrary other processes as specified by a user in a configuration file.
Batch script B is one such process a user would like to be invoked by A. B sets up some environment variables, shows some messages and invokes a compiler C to do some work.
Does Windows provide a standard way for arbitrary processes to be terminated cleanly? Suppose A is run in a console and receives a CTRL+C. Can it pass this on to B and C? Suppose A runs in a window and the user tries to close the window, can it cancel B and C?
TerminateProcess is an option, but not a very good one. If A uses TerminateProcess on B, C keeps running. This could cause nasty problems if C is long-running, since we might start another instance of C to operate on the same files while the first instance of C is still secretly at work. In addition, TerminateProcess doesn't result in a clean exit.
GenerateConsoleCtrlEvent sounds nice, and might work when everything's running in a console, but the documentation says that you can only send CTRL+C to your own console, and so wouldn't help if A were running in a window.
Is there any equivalent to SIGINT on Windows? I would love to find an article like this one: http://www.cons.org/cracauer/sigint.html for Windows.
© Stack Overflow or respective owner