我可以通过任务管理器处理我的 Windows 进程的终止吗? [英] Can I handle the killing of my windows process through the Task Manager?

查看:93
本文介绍了我可以通过任务管理器处理我的 Windows 进程的终止吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Windows C++ 应用程序 (app.exe).当应用程序关闭时,我需要执行一些特定于我的应用程序的清理任务.当这个进程 (app.exe) 通过任务管理器被终止时会发生什么.假设应用程序仍然响应,我可以在我的 app.exe 中以某种方式处理这种情况吗?

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

我正在寻找类似于 kill <pid> 在 Linux 中如何将 SIGTERM 信号发送到由 pid 指示的进程的东西.然后我可以为 SIGTERM 注册我自己的信号处理程序并执行清理.

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

推荐答案

在任务管理器中有两种杀死应用程序的方法.

There are two ways to kill application in Task Manager.

  • 通过应用程序选项卡杀死大致相当于SIGTERM.应用程序可能会拦截它并进行更多处理,因为它基本上是发送关闭窗口"消息.要捕获的消息是 WM_CLOSE.
  • 通过Processes 选项卡杀死大致相当于SIGKILL.除了在任务管理器的列表框和结束进程按钮中监控用户的操作,或者有一个看门狗进程可以看到第一个被杀死的时间,你无法拦截它.
  • Killing through Applications tab would roughly be equivalent of SIGTERM. Application may intercept it and do more processing, since it's basically sending a "close window" message. Message to catch is WM_CLOSE.
  • Killing through Processes tab would roughly be equivalent of SIGKILL. There is nothing you can do to intercept that, short of monitoring user's actions in Task Manager's listbox and End Process button, or having a watchdog process that will see when the first one is killed.

或者,以不需要清理或在启动时执行清理的方式设计应用程序.

Alternatively, design the application in a way that does not require cleanup, or in a way that it will perform cleanup at startup.

这篇关于我可以通过任务管理器处理我的 Windows 进程的终止吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆