Windows – How to kill a Windows Process that refuses to die

killwindows

Running Windows Server 2003, I have some processes that when killed take a a few minutes of 100% cpu to die.

Using Process Explorer to view the processes threads I always see 2 threads, with one of them using lots of cpu and stuck in !endthreadex

Any idea what could cause these processes to not-die for so long?
Is there any way for me to force kill such a process?

Best Answer

When you try to kill a process, Windows will first attempt to end it gracefully through the normal code paths before taking it down forcefully. The reason why it's stuck at 100% CPU is most likely that you have a loop or similar in your tear down that is spinning around waiting for something to happen (e.g. like a database connection to completely close) without a Thread.Sleep in it. It's possible that the something it's waiting for never happens (owing to the abnormal exit caused by killing it) and so it's stuck until Windows decides to take it down by force. Examine your shutdown code for the process and you should find the culprit for that.

Appropriate for SO at this stage, I would think.