我可以通过任务管理器处理我的 Windows 进程的终止吗?

编程入门 行业动态 更新时间:2024-10-21 11:29:58
本文介绍了我可以通过任务管理器处理我的 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 进程的终止吗?

本文发布于:2023-11-27 08:27:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637280.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以通过   任务管理器   进程   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!