On Windows 7, how to send Ctrl-C or Ctrl-Break to a separate process

Our group has long-term processes that run daily. Typically, these processes start at 9pm any day and run until 7pm the next day. Thus, they usually work 22 hours a day. They are run by scheduled tasks on servers under a specific common user ID, and they run and run regardless of whether or not that user ID is registered. Thus, they are windowless console executables.

Tasks organize computations that are performed on a large server farm. Typically, these control tasks run smoothly for 22 hours a day. However, we often have to stop and restart these processes. Because they manage many of the tasks that run on our server farm, it is important that they are shut down so that they can stop and shut down all processes in the server farm. This brings me to our problem.

The control process is programmed to respond to the ctrl-C and ctrl-break signals. This works great when the process is started manually in the console, where we have access to the console and we can "type" ctrl-c or ctrl-break in the console window. However, as already mentioned, processes usually run as scheduled tasks without windows. Therefore, we cannot "enter" anything into a non-existent console window. Since they are console processes that run without a login process, they must also be executed in a completely windowless manner. So how do we set up the process to listen for the disconnect signal?

While the process is actually listening for the ctrl-C and ctrl-break signal, I see no way to send that signal to the process. This seems to be a fundamental issue on Windows, or am I wrong? I know SendSignal.exe but still couldn't get it to work. It doesn't work like this:

>SendSignal 26320
Sending signal to process 26320...
CreateRemoteThread failed with 0x00000005.
StartRemoteThread failed with 0x00000005.
0x00000005 == Access is denied.

      

Attempting "taskkill" without -F results in:

>taskkill /PID 24840
ERROR: The process with PID 24840 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option). 

      

All other kill functions kill the process immediately instead of sending a signal.

One possible solution would be a file based solution: create a chat for some modification of a specific file. But this is a hack, and we would rather do it with the appropriate alarm. Has anyone solved this problem? This seems to be a very simple functionality and it is of course trivial to do it in a Unix environment. Has Microsoft provided a SOME mechanism to ensure the clean completion of the windowless executable?

I am aware of the following thread, the question of which is almost identical (except for the specification of why an answer is needed i.e. why one should be able to do this for a windowless process without a console), but there is no answer there expet for "use SendSignal". which, as I said, doesn't work for us:

Is it possible to send ctrl-C (SIGINT) to an application on Windows?

There are other similar questions, but there are no answers yet.

Any help was appreciated.

+3


source to share





All Articles