403

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.

Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265
Eli Courtwright
  • 186,300
  • 67
  • 213
  • 256
  • 22
    Stray processes is a common enough problem in programming that I have to disagree; this is not an off-topic question. – Dan Moulding Sep 03 '15 at 18:10
  • 23
    I deal with process management every day as a developer. This is totally ON topic for me! – John Fitzpatrick Oct 05 '15 at 19:25
  • 17
    I strongly advise against deleting this question. +195 and it's a really early google hit for the question involved. – Joshua Apr 26 '16 at 20:38
  • 2
    "unless they directly involve tools used primarily for programming" I ran into this issue in regards to Visual Studio keeping a process running which made me unable to kill it. Closing Visual Studio helped kill the problematic process. – Joakim Jul 25 '16 at 14:18
  • You can use the [Stop-Process powershell cmdlet](https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.management/stop-process). – Rosberg Linhares Dec 12 '16 at 16:36
  • Aaaaaaaaaand it's closed :/ – Aaron Franke Dec 04 '17 at 07:01
  • If another program has a reference to the process handle the program won't exit until released. It's known as a zombie program - there is nothing left in the program. If it was to exit it would cause the other program to crash. – Noodles Apr 11 '19 at 06:29

11 Answers11

333

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

pilif
  • 12,548
  • 5
  • 34
  • 31
  • 31
    While I hate that this is the correct answer, there's no doubt in my mind that it is more correct than taskkill below.... stupid buggy drivers! – codetaku Jul 22 '13 at 21:03
  • 6
    Slighly less annoying than a reboot is to log off/on again. Still lose work, but not quite so much time perhaps. – awidgery Sep 17 '13 at 13:19
  • 2
    Apparently this is not the "most ultimate way" to kill a process. There are some processes in Windows where after you destroy them with Task Manager they just instantly respawn as if nothing happened... :/ – rgajrawala Jul 10 '14 at 03:22
  • 9
    that's caused by some other process making sure the initial process is always running. You killed your old instance and a new one has been started by the watchdog – pilif Jul 11 '14 at 06:01
  • How can I know what is making this process go into uninterruptible sleep? – sliders_alpha Sep 21 '14 at 14:28
  • 9
    This answer is **not** correct at all. "End Process" is not the most ultimate way to kill processes, as it can't kill service processes (for example). `taskkill /f` is the most ultimate. – user626528 Jan 14 '15 at 07:03
  • This should not be the accepted answer. The equivalent of Linux's "kill -9" command is the command "TaskKill /f". Obviously it needs to be run in an elevated command prompt. – user2268788 Mar 24 '15 at 05:41
  • 8
    TaskKill /f only calls the `TerminateProcess` API. It does exactly the same thing as the Task Manager (though, you're right on that, with elevated privileges). – pilif Mar 24 '15 at 12:31
  • 1
    Using Task Manager alone to try to kill a process is equivalent to calling TaskKill without the /f option. – user2268788 Mar 26 '15 at 02:27
  • @colacX it's an error not a feature. It's stuck waiting for a signal so it can't hear any signals to end. – Mike May 21 '15 at 19:36
  • 1
    In Windows 8, Task Manager no longer has the "End Process" button. It only has the "End Task" button, which attempts to terminate a process in a much gentler way. – Throw Away Account Jun 03 '15 at 13:50
  • 1
    @ThrowawayAccount3Million No, it just hides it better - you'll find the old list of processes with the familiar `TerminateProcess`-calling button on the Details tab :) – Luaan Oct 22 '15 at 11:55
  • I had success just now killing an unkillable java.exe process, using the info here that it might be waiting on a device driver. I disconnected the serial connection that I knew it was listening to, and the process died immediately. – Phil Goetz Aug 23 '18 at 20:34
  • 1
    A cached version of the dead link: https://web.archive.org/web/20090530042534id_/http://blogs.technet.com/markrussinovich/archive/2005/08/17/unkillable-processes.aspx – Vladimir Reshetnikov Jun 12 '20 at 01:20
  • In my case an instance of the Tomcat server won't shut down. Neither with 'End Process' nor with taskkill or the process explorer. I've used admin rights for all the cases, but the message 'Access denied' appears. This is hardly a driver problem. Any ideas how this can be analyzed or how the root cause can be found out? – Klendatho Nov 19 '21 at 04:50
  • @Klendatho Isn't Tomcat running as a service? Why not just stop the service then? – The incredible Jan Oct 17 '22 at 06:55
  • @TheincredibleJan It is running as a service. But sometimes Windows is not able to stop a service. That can happen if Tomcat has run out of memory. Then it takes either very long (many hours!) until the process is stopped or the server needs to be restarted. What cannot be done at any time on a production server. – Klendatho Oct 24 '22 at 06:14
263
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.

JosephStyons
  • 57,317
  • 63
  • 160
  • 234
  • 10
    Just a note. This is particularly useful if you are writing scripts for server management. kill.exe (from the NT Res kit) will cause a program to exit, but if you have a crash handler installed (particularly windbg), it can cause issues as the OS will see the killed process as having crashed, and attempt to debug it. Taskkill will not result in this issue. – Aaron Oct 02 '09 at 14:43
  • I guess the taskmanager call taskkill internally? they are actually samething? – Baiyan Huang Oct 17 '12 at 08:57
  • 6
    @lzprgmr - taskkill and "end task" probably both call the same underlying windows function "TerminateProcess" http://msdn.microsoft.com/en-us/library/windows/desktop/ms686714%28v=vs.85%29.aspx – JosephStyons Oct 17 '12 at 14:51
  • 65
    THis is no more effective then "end process" from task manager. – Eddie Apr 07 '13 at 12:58
  • 1
    Using `/T` will also kill any processes started by that process (like using "end process tree" in task manager) – Kip Sep 19 '13 at 12:58
  • 2
    I've been trying to forcefully kill SugarSync.exe without having to reboot (since restarting SugarSync twice before it really gets going makes it work again), but taskkill /T /F /IM SugarSync.exe doesn't work--even though it claims "SUCCESS" – Jon Coombs Apr 02 '14 at 22:38
  • Based on other answers I've found online, I tried again, this time using PsExec -sid cmd.exe , verifying with whomai that I am indeed "nt authority\system", and running taskkill /T /F /IM SugarSync.exe . (From Sysinternals.) No dice. It again claims "SUCCESS" but the process is still showing in Task Manager. Ditto if I find the process ID and run pskill -t 5652 – Jon Coombs Apr 02 '14 at 23:11
  • Beautiful, I have been looking for this command forever (I should note that I came here looking for a way to end process from the command line, so the fact that it is not "more powerful is ok with me) – Jeff Davis Jul 21 '14 at 15:01
  • Taskkill is not a general windows 7 command (only in the ultimate or professional). Only the much inferior tskill is part of all recent windows versions. – Lothar Dec 27 '14 at 20:06
  • 3
    THANK YOU! `taskkill /pid 1234 /f` does work when _End Task_ refuses to work! WOW! – Hendy Irawan Apr 28 '15 at 16:09
  • 2
    @Eddie. This IS more effective then "end process" from task manager. I just killed a process with it, task manager refused to kill. Even if it may run the same code under the hood (I'm not saying it does) you have the freedom to run this command with different privilege levels. – Slava Sep 28 '17 at 09:55
  • 1
    `ERROR: The process "RMPARTUSB.exe" with PID 5224 could not be terminated. Reason: There is no running instance of the task` If there's no running instance how does it have a PID? – Aaron Franke Jan 02 '18 at 05:29
  • @AaronFranke Try "tasklist" and note the PID beside RMPARTUSB.exe in that list. Then run taskkill /pid ### with the correct PID in place of ###. – JosephStyons Jan 02 '18 at 05:46
  • 1
    @Slava: You were using the wrong button in Task Manager. "End Task" button sends a polite request, similar to `kill -TERM` "End Process" button calls `TerminateProcess`, similar to `kill -9` – Ben Voigt Jul 05 '22 at 15:49
  • "different privilege levels" are not a valid argument - you can run task manager with "different privilege levels", too. – The incredible Jan Oct 17 '22 at 06:59
41

Process Hacker has numerous ways of killing a process.

(Right-click the process, then go to Miscellaneous->Terminator.)

user541686
  • 205,094
  • 128
  • 528
  • 886
29

JosepStyons is right. Open cmd.exe and run

taskkill /im processname.exe /f

If there is an error saying,

ERROR: The process "process.exe" with PID 1234 could not be terminated. Reason: Access is denied.

then try running cmd.exe as administrator.

Shades
  • 5,568
  • 7
  • 30
  • 48
Dhruv Chandhok
  • 780
  • 7
  • 18
  • 13
    Running as administrator, the error changes. It now says: `ERROR: The process with PID 17888 (child process of PID 17880) could not be terminated. Reason: There is no instance of the task.` and it is referring to the parent PID 17880. As it can't find the parent, it won't kill the orphaned child. :( – Jesse Chisholm Jun 07 '15 at 14:58
  • 1
    "you must kill child process too if any spawned to kill successfully your process" try this http://stackoverflow.com/questions/12528963/taskkill-f-doesnt-kill-a-process – Dhruv Chandhok Jun 08 '15 at 10:26
  • In my case, the zombie process I told it to kill was the **only** child and there was no parent, though the zombie still thought it had a parent. In my case, resolved by using the Windows 8.1 Settings Advanced Repair System path, but canceling from actually wiping any disk, and just doing a full forced reboot. The regular shutdown and reboot is really sleep/hibernation (to save time on startup). Non-trivial getting it to do a _full_ shutdown. – Jesse Chisholm Jun 09 '15 at 13:12
  • "Access is denied" means that the process is already in the process of being closed. For example if you had just attempted to close it earlier. You'll need to wait till it gets closed. – Pacerier Jul 20 '16 at 21:14
  • 1
    taskkill results under admin rights: Access is denied. – amuliar Apr 11 '18 at 11:12
22

Get process explorer from sysinternals (now Microsoft)

Process Explorer - Windows Sysinternals | Microsoft Docs

Iain Holder
  • 14,172
  • 10
  • 66
  • 86
  • 17
    That does provide more info (and some limited ability to search for lock handles) but I've not had any more success at killing tasks with it than with basic Task Manager. Certain processes (like anti-virus, and SugarSync.exe) simply refuse to die. – Jon Coombs Apr 02 '14 at 22:39
16

One trick that works well is to attach a debugger and then quit the debugger.

On XP or Windows 2003 you can do this using ntsd that ships out of the box:

ntsd -pn myapp.exe

ntsd will open up a new window. Just type 'q' in the window to quit the debugger and take out the process.

I've known this to work even when task manager doesn't seem able to kill a process.

Unfortunately ntsd was removed from Vista and you have to install the (free) debbugging tools for windows to get a suitable debugger.

Rob Walker
  • 46,588
  • 15
  • 99
  • 136
  • 1
    Thank you SO MUCH for this. Add "-c q" (w/o quotes) to autoquit, which makes it ideal process killer. – Joanis May 10 '12 at 21:43
  • 2
    When Visual Studio and an application being debugged both hang, attach and kill the old instance of VS. The killer can be a new instance of VS, which can then open the old project and allow you to continue working. – Bruno Martinez Oct 25 '13 at 23:30
  • I can't figure out how to download anything from that link other than `winsdk_web.exe`, which does nothing. – endolith Mar 17 '14 at 19:57
  • You can now get it in the Windows 10 SDK by running the installer and then unchecking everything but "Debugging Tools for Windows" (https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/#install-debugging-tools-for-windows) – Cobertos May 24 '20 at 09:12
  • this doesn't work if the unkillable process is something you were debugging when VS crashed, since the phantom process still believes it's attached to a debugger. Even invoking VS again and trying to attach back will error. I had to restart my computer. – eri0o Oct 04 '22 at 00:31
6

setup an AT command to run task manager or process explorer as SYSTEM.

AT 12:34 /interactive "C:/procexp.exe"

If process explorer was in your root C drive then this would open it as SYSTEM and you could kill any process without getting any access denied errors. Set this for like a minute in the future, then it will pop up for you.

David Ruark
  • 69
  • 1
  • 1
  • 4
    I get the following warning when trying this, so it seems to no longer work: "Warning: Due to security enhancements, this task will run at the time expected but not interactively. Use schtasks.exe utility if interactive task is required ('schtasks /?' for details)." – WhiteKnight Jan 03 '14 at 08:52
1

FYI you can sometimes use SYSTEM or Trustedinstaller to kill tasks ;)

google quickkill_3_0.bat

sc config TrustedInstaller binPath= "cmd /c TASKKILL /F  /IM notepad.exe
sc start "TrustedInstaller"
RmccurdyDOTcom
  • 173
  • 1
  • 7
1

I had this issue too, here is how I solved it.

1/ Open the « task manager « 

2/ Locate the application name in the list

3/ Once found, right click on its name then click on « properties »

4/ In the properties interface, click on « security « 

5/ Click on « edit » to change permissions

6/ « Deny » all permissions for all users, click on «  apply » then « ok »

7/ click on « advanced » for special permissions settings

8/ Remove permissions for all users

9/ click on «  apply » then « ok »

10/ click on «  apply » then « ok » again

11/ you can now kill the process on task manager as well as uninstall the app of you want to.

0

wmic process where processid="11008" call terminate

Monsignor
  • 2,671
  • 1
  • 36
  • 34
0

When ntsd access is denied, try:

ZeroWave was designed to be a simple tool that will provide a multilevel termination of any kind of process.

ZeroWave is also a easy-to-use program due to its simple installation and its very friendly graphical interface.

ZeroWave has three termination modes and with the "INSANE" mode can terminate any kind of process that can run on Windows.

It seems that ZeroWave can't kill avp.exe

diyism
  • 12,477
  • 5
  • 46
  • 46