I have a Windows Console application that will be running for an extended period of time. This has been developed in house and tests have shown that over time memory usage grows and other bad things ensue. The Developers can't correct all the issues in time for release, so I'm looking for a way to end and restart the process on a periodic basis. I already have a Windows Scheduled task that runs a batch file, checks if the process is running and if not, starts it.

Now I need something that stops it gracefully. The application has commandeered the CTRL-BREAK event as a request for a controlled shutdown. I'd like to send it that CTRL-BREAK and if it still doesn't end after some period of time, then I could use taskkill to end it forcefully. taskkill seems to feed it a CTRL-CLOSE event. Is there some way to feed CTRL-BREAK to a process from the command line?


You can send a control-break with this little utility.


note Make sure to use start if you are running it from a batch file.

| improve this answer | |
  • Yeah, I actually did see that one. I was hoping there was some built-in windows tool or utility to accomplish this so I wouldn't have to package up that .exe with my application. That might be an option though if there's no other way to do this. – Mutmansky Mar 20 '12 at 13:50
  • You aren't going to be able to do this without third party. That abort signal has to be sent by a process that is attached to the same console window (input buffer technically). – Nate Mar 20 '12 at 16:20
  • If this is being developed in house why don't you have them do some other type of hack such as if a specific file exists in the program directory do the graceful shutdown. That would be quite easy to implement and could be used by a batch file to terminate it and then restart the app. – Nate Mar 20 '12 at 16:22

I don't know if a break event is considered a graceful close for an application.

That said, search for the ps utilities under sysinternals, free from Microsoft. There is a pskill command that can be used to kill applications and I believe a pslist to get process ID's. Parse it out and send a kill signal to it, see if that works for you.

| improve this answer | |
  • As I said, this particular application was specifically engineered to handle CTRL-BREAK as a graceful shutdown request (as opposed to CTRL-C, CTRL-CLOSE, etc.). After some quick googling, I can't see any options on pskill that would make the result any different from taskkill. – Mutmansky Mar 20 '12 at 13:42
  • I didn't say it wasn't engineered to handle that as a graceful shutdown. I said I wouldn't call that a graceful close, as in it's kind of a dirty workaround for a problem. I wasn't sure what event pskill uses or could use specifically, or if the application could be modified to use a different sequence from pskill. – Bart Silverstrim Mar 20 '12 at 13:50
  • I can't see any way to have pskill (or taskkill for that matter) send a specific sequence. taskkill always seems to send CTRL-CLOSE, I didn't try pskill specifically, but I haven't found any documentation so far that indicates it does otherwise. Besides, it doesn't seem to exist on Win7 by default at least. – Mutmansky Mar 20 '12 at 13:57
  • It doesn't, you download it as part of the sysinternals suite from MS. Free download with a lot of other useful tools. – Bart Silverstrim Mar 20 '12 at 13:59
  • If you launch a process such a 7z.exe (7-Zip), you know two things... killing the process leaves a corrupt file behind, but pressing ctrl-break results in a graceful shutdown where the file is deleted. Therefore, we need to be able to send a ctrl-break or equivalent signal to such a process, which is a 3rd-party application that already exists, can't be modified, and hasn't been engineered to shut down gracefully in any other way than ctrl-break. From what I've read, ctrl-break causes a remote thread to be created in the target process with an entry point of "kernel32!CtrlRoutine". – Triynko Apr 19 '13 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.