是否可以在不取消调用堆栈的情况下终止Windows XP上的C ++应用程序? [英] Is it possible to kill a C++ application on Windows XP without unwinding the call stack?

查看:103
本文介绍了是否可以在不取消调用堆栈的情况下终止Windows XP上的C ++应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是,当您通过Windows XP中的任务管理器杀死C ++应用程序时,该应用程序仍然被干净地破坏了-即,调用堆栈将展开并且所有相关的对象析构函数将被调用。不确定我的理解是否是错误的。



是否有可能在不取消堆栈的情况下立即杀死此类应用程序?



例如,应用程序可以使用RAII模式,该模式将在对象被破坏时破坏或释放资源。如果通过任务管理器进行的传统杀死过程很正常,那么提供一种立即杀死该应用程序的方法将使我能够测试不正常的关机(例如断电)。



编辑:



我只是想说明一下,我是在使用允许我执行此操作的现有实用程序或程序。我应该能够在我没有源代码的程序上使用该解决方案,这意味着编程解决方案并不是真正可以接受的。



编辑:



只是为了提供更多上下文,有时我不得不使用非常麻烦的第三方服务(例如,让我每小时重新启动一次)。由于我知道我不需要重新启动,因此我想终止该进程/服务,这样就不再烦我了。不幸的是,一些第三方开发人员足够聪明,可以阻止我执行此操作,当我通过任务管理器终止该进程时,系统将立即重新启动(我猜这是使用RAII来实现的)。

此调用应立即终止该进程,而不会发出警告:



TerminateProcess



例如:

  TerminateProcess(GetCurrentProcess(),1); 

更新:



您可能会发现有趣的文章:



退出时间:退出C ++程序



更新2:


我应该可以使用对于我没有源代码的程序的解决方案


嗯,这是99.9%的时间的不良行为。



SysInternals有一个名为 pskill 的实用程序:



http://technet.microsoft.com/en-us/sysinternals/bb896683.aspx



,但我不确定它的好程度。



您可能需要自己动手,但这应该很容易:

  DWORD pid =<从命令行获取pid> ;; 

TerminateProcess(OpenProcess(PROCESS_TERMINATE,FALSE,pid));


My understanding is that when you kill a C++ application through Task Manager in Windows XP, the application is still "cleanly" destructed - i.e. the call stack will unwind and all the relevant object destructors will be invoked. Not sure if my understanding is wrong here.

Is it possible to kill such an application immediately, without unwinding the stack?

For example, the application may employ RAII patterns which will destroy or release resources when an object is destructed. If the traditional "kill process" through Task Manager is graceful, providing a way to kill the application immediately would allow me to test ungraceful shutdown (e.g. a power outage).

Edit:

Just to clarify, I was after an existing utility or program that would allow me to do this. I should be able to use the solution on programs that I don't have the source code for, meaning that a programmatic solution is not really acceptable.

Edit:

Just to provide more context, sometimes I have to work with 3rd party services which are very intrusive (e.g. nagging me to reboot every hour). Since I know that I don't need to reboot, I want to kill the process/service so it doesn't nag me anymore. Unfortunately some of the 3rd party developers were "smart" enough to prevent me from doing this, and when I kill the process through Task Manager, the system will reboot immediately (I'm guessing that are using RAII to achieve this).

解决方案

I believe task manager tries a "nice" shutdown by sending a WM_CLOSE message, then if the application doesn't respond it's killed.

This call should kill the process immediately with no warning:

TerminateProcess

e.g.:

TerminateProcess(GetCurrentProcess(), 1);

Update:

You may find this article interesting:

Quitting time: exiting a C++ program

Update 2:

I should be able to use the solution on programs that I don't have the source code for

Hmm, well this is undesirable behavior 99.9% of the time.

SysInternals has a utility called pskill:

http://technet.microsoft.com/en-us/sysinternals/bb896683.aspx

but I'm not sure how "nice" it is.

You might need to roll your own, but it should be pretty easy:

DWORD pid = <get pid from command line>;

TerminateProcess(OpenProcess(PROCESS_TERMINATE, FALSE, pid));

这篇关于是否可以在不取消调用堆栈的情况下终止Windows XP上的C ++应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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