Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Really killing a process in Windows

Tags:

windows

Occasionally a program on a Windows machine goes crazy and just hangs. So I'll call up the task manager and hit the "End Process" button for it. However, this doesn't always work; if I try it enough times then it'll usually die eventually, but I'd really like to be able to just kill it immediately. On Linux I could just kill -9 to guarantee that a process will die.

This also could be used for writing batch scripts and writing batch scripts is programming.

Is there some program or command that comes with Windows that will always kill a process? A free third-party app would be fine, although I'd prefer to be able to do this on machines I sit down at for the first time.

like image 362
Eli Courtwright Avatar asked Sep 08 '08 15:09

Eli Courtwright


People also ask

How do I completely kill a process?

There are two commands used to kill a process: kill – Kill a process by ID. killall – Kill a process by name.

How do I kill a process immediately?

When no signal is included in the kill command-line syntax, the default signal that is used is –15 (SIGKILL). Using the –9 signal (SIGTERM) with the kill command ensures that the process terminates promptly.

How do you kill a process in CMD?

A. A. Usually to stop a process, you start task manager, select the Processes tab, select the process and click "End Process" however you can also accomplish the same from the command prompt using 2 Resource Kit utilities.


2 Answers

"End Process" on the Processes-Tab calls TerminateProcess which is the most ultimate way Windows knows to kill a process.

If it doesn't go away, it's currently locked waiting on some kernel resource (probably a buggy driver) and there is nothing (short of a reboot) you could do to make the process go away.

Have a look at this blog-entry from wayback when: http://blogs.technet.com/markrussinovich/archive/2005/08/17/unkillable-processes.aspx

Unix based systems like Linux also have that problem where processes could survive a kill -9 if they are in what's known as "Uninterruptible sleep" (shown by top and ps as state D) at which point the processes sleep so well that they can't process incoming signals (which is what kill does - sending signals).

Normally, Uninterruptible sleep should not last long, but as under Windows, broken drivers or broken userpace programs (vfork without exec) can end up sleeping in D forever.

like image 104
pilif Avatar answered Sep 18 '22 12:09

pilif


taskkill /im myprocess.exe /f 

The "/f" is for "force". If you know the PID, then you can specify that, as in:

taskkill /pid 1234 /f 

Lots of other options are possible, just type taskkill /? for all of them. The "/t" option kills a process and any child processes; that may be useful to you.

like image 21
JosephStyons Avatar answered Sep 20 '22 12:09

JosephStyons