4

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.

2
  • 2
    Do you know of any circumstances other than permissions failure under which TerminateProcess will fail? Commented Aug 23, 2010 at 13:36
  • 1
    @James: If the process is running kernel mode code, it may not be terminated. Add a dash of poorly written driver code and you can definitely get into infinite loops that can't be recovered from. Commented Aug 23, 2010 at 13:48

1 Answer 1

9

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).

Sign up to request clarification or add additional context in comments.

3 Comments

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).
How about process explorer (from sysinternals)? I've even killed svchost from procexpl (not wise)
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.