Can I handle the window processing in the task manager?

I have a Windows C ++ application (app.exe). When the application is closed, I need to perform some cleaning tasks specific to my application. What happens when this process (app.exe) is killed through the Task Manager. Assuming the application is still responding, can I somehow handle this situation in my app.exe?

I am looking for something similar to how kill <pid> on Linux will send a SIGTERM signal to the process indicated by pid. Then I could register my own signal handler for SIGTERM and do the cleanup.

+4
source share
3 answers

There are two ways to kill an application in task manager.

  • Descending through the Applications tab is roughly equivalent to SIGTERM . An application can intercept it and do more processing, as it basically sends a “close window” message. Message for catch WM_CLOSE .
  • Descending through the Processes tab is roughly equivalent to SIGKILL . You can’t do anything to intercept this without waiting for control over the user’s actions in the list of the task manager and the “End the process” button, or with the watchdog process that will see when the first one is killed.

Alternatively, create the application in such a way that it does not require cleaning, or so that it performs cleaning at startup.

+9
source

I think you will need another PID that controls the PID of your app.exe and does the necessary work at that time.

0
source

It depends on whether the user selects "Complete the task" your application, and you can process it. see this.

but if the user decided to complete the process, you have no way to process it in the application. the easiest way is the second process, or you can enter into the process manager and connect the TerminateProcess API.

0
source

All Articles