tags:

views:

105

answers:

1

In C++ is there a way to unconditionally kill a process?

No matter what state this process is in.

I know about TerminateProcess, but it can still fail. What if you don't want it to fail.

Like when you kill a process in Task Manager, it dies; no matter what. That's the kind of killing I'm looking for.

+7  A: 

Not every process can be killed from Task Manager. This depends both on permissions and on process state. Some processes, hung in winsock can't be killed (and even Task Manager will hang).

joekoyote
True. And killing some processes (esp. some system services, like RPC server) will bring down your whole system (artificially yet automatically), for stability reasons (a 30-sec shutdown prompt pops up). But other than that, `TerminateProcess` is the best bet you have in Windows (incidentally, that's what Task Manager does).
Piskvor
How about process explorer (from sysinternals)? I've even killed svchost from procexpl (not wise)
Default
process explorer uses undocumented internals of the system (maybe even kernel-mode stuff, I didn't check). There's a lot you can this way, yet process explorer sometimes also can't kill a process (if the process is blocked in the kernel). svchost is a user-mode process, so it's just a permissions question.
joekoyote