Is it possible to kill a C ++ application on Windows XP without expanding the call stack?
I understand that when you kill a C ++ application using the Task Manager on Windows XP, the application is still "cleaned up" completely, i.e. the call stack is expanded, and all appropriate object destructors will be invoked. Not sure if my understanding is wrong here.
Is it possible to immediately kill such an application without unwinding the stack?
For example, an application can use RAII templates that will destroy or free resources when an object is destroyed. If the traditional "kill process" with the task manager is graceful, providing a way to kill the application immediately will allow me to check for disrespectful shutdowns (like power outages).
Edit:
Just to clarify, I was behind an existing utility or program that would allow me to do this. I should be able to use the solution for programs for which I do not have the source code, which means that the software solution is not very acceptable.
Edit:
To provide more context, I sometimes have to work with third party services that are very intrusive (for example, forcing me to reboot every hour). Since I know I don't need to reboot, I want to kill the process / service so that it doesn't overtake me anymore. Unfortunately, some third-party developers were smart enough to stop me from doing this, and when I kill this process through the task manager, the system will restart immediately (I'm assuming RAII is used to achieve this).
source to share
I believe the task manager is trying to "nicely" shut down by sending a WM_CLOSE message, and then if the application doesn't respond, it gets killed.
This call should kill the process immediately without warning:
eg:.
TerminateProcess(GetCurrentProcess(), 1);
Update:
You may find this article interesting:
Update 2:
I should be able to use a solution for programs for which I do not have source code for
Hmm, well, this is unwanted 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 may need to collapse yourself, but this should be pretty easy:
DWORD pid = <get pid from command line>;
TerminateProcess(OpenProcess(PROCESS_TERMINATE, FALSE, pid));
source to share
The standard Windows way of doing this without relying on third-party tools is to use taskkill /f
:
taskkill /f <process-id>
taskkill /f /im <process-executable-name>
/f
means "force" here and guarantees that the process will be completed unconditionally and immediately, without asking or warning.
source to share
If I'm not mistaken (and I just did a little testing to confirm), Task Manager tries to close programs differently depending on which tab you are using. If you go to the Applications tab and click End Task, it will try to close the program completely by first sending a WM_CLOSE. But if you go to the Processes tab and click End Process, it looks like something is using TerminateProcess lines, which means there is no stack unwinding, etc.
So, if you are not using End Process in Processes tab, try this.
If what you've already tried and their software still manages to reboot the system somehow, then something more complicated is happening. Other people may be on the right track about having additional processes.
source to share
It looks like abort () will give you abnormal output.
ANSI 4.10.4.1 Abort behavior relative to open and temporary files The abort function does not close files that are open or temporary. It does not flush stream buffers [source]
and
Abort current process Abort the process with abnormal program termination. The function generates the SIGABRT signal, which by default causes the program to terminate> return a failed termination error code to the host environment. The program exits without executing destructors for objects, automatic or static storage time, and without calling any atexit function. The function never returns to the caller. [source]
source to share
I would try PSKill as suggested by Tim above . I would guess that it won't succeed either. If third party services are really serious about avoiding death, then the service definition can be configured to "reboot on failure". Another common approach is to have another service that controls the main one. The main service usually sets up a global event or uses another notification mechanism that the watchdog service observes. If the primary service does not notify the watchdog timer, the watchdog timer restarts the computer.
source to share
Aptly named , available from Microsoft Download. Also part of the Windbg package. Kill Tool
The Kill tool, kill.exe, kills one or more processes and all of their threads. This tool only works with processes running on the local computer.
kill /f <process>
For example, kill /f lsass
(just kidding, don't kill the LSA!). If you want to roll your own, TerminateProcess is the way to go.
source to share
The ab ab () function in the standard library will immediately destroy your application without cleaning up.
C ++ defines a standard global terminate () function. Calling it will also exit the application instantly.
Technically, the terminate () method can be overridden by the set_terminate function. It is interrupted by default.
source to share
There are utilities that can prevent reboots.
HideToolz does this for example - there is somewhere somewhere that a checkbox will be checked that will make it ask you when something triggers a reboot. It is detected by many antiviruses as a rootkit (which it is, but this one is presumably a manual one), so it can be problematic to work on systems on which you do not have full control (when the antivirus provided by the domain policy, etc.)
source to share