在 Windows 中真正杀死一个进程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Really killing a process in Windows
提问by Eli Courtwright
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.
有时,Windows 机器上的程序会发疯并挂起。所以我会调用任务管理器并点击“结束进程”按钮。然而,这并不总是有效。如果我尝试足够多次,它通常最终会死亡,但我真的希望能够立即杀死它。在 Linux 上,我可以kill -9
保证一个进程会死亡。
This also could be used for writing batch scripts and writing batch scripts is programming.
这也可用于编写批处理脚本,编写批处理脚本就是编程。
Is there someprogram 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.
是否有一些Windows 附带的程序或命令总是会杀死一个进程?免费的第三方应用程序就可以了,尽管我更希望能够在我第一次坐下的机器上执行此操作。
采纳答案by pilif
"End Process" on the Processes-Tab calls TerminateProcess
which is the most ultimate way Windows knows to kill a process.
Processes-Tab 调用上的“结束进程”,TerminateProcess
这是 Windows 知道杀死进程的最终极方式。
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
在以下时间查看此博客条目: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).
像 Linux 这样的基于 Unix 的系统也存在这样的问题,如果进程kill -9
处于所谓的“不间断睡眠”(由 top 和 ps 显示为 state D
),那么进程可以继续存在,此时进程睡眠如此之好以至于它们无法处理传入的信号(这就是kill
- 发送信号)。
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.
通常,不间断睡眠不会持续很长时间,但在 Windows 下,损坏的驱动程序或损坏的用户空间程序(vfork
没有exec
)最终可能会D
永远处于睡眠状态。
回答by JosephStyons
taskkill /im myprocess.exe /f
The "/f" is for "force". If you know the PID, then you can specify that, as in:
“/f”代表“力”。如果您知道 PID,那么您可以指定它,如下所示:
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.
许多其他选项都是可能的,只需键入 taskkill /? 对于他们所有人。"/t" 选项会杀死一个进程和任何子进程;这可能对你有用。
回答by user541686
Process Hackerhas numerous ways of killing a process.
Process Hacker有多种杀死进程的方法。
(Right-click the process, then go to Miscellaneous->Terminator.)
(右键单击该进程,然后转到 Miscellaneous->Terminator。)
回答by Dhruv Chandhok
JosepStyons is right. Open cmd.exe and run
JosepStyons 是对的。打开cmd.exe并运行
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.
错误:无法终止 PID 为 1234 的进程“process.exe”。原因:访问被拒绝。
then try running cmd.exe as administrator.
然后尝试以管理员身份运行 cmd.exe。
回答by Iain Holder
Get process explorer from sysinternals (now Microsoft)
从 sysinternals(现在的 Microsoft)获取进程资源管理器
回答by Rob Walker
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:
在 XP 或 Windows 2003 上,您可以使用开箱即用的 ntsd 执行此操作:
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.
ntsd 将打开一个新窗口。只需在窗口中键入“q”即可退出调试器并退出进程。
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 windowsto get a suitable debugger.
回答by David Ruark
setup an AT command to run task manager or process explorer as SYSTEM.
设置 AT 命令以作为 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.
如果进程资源管理器在您的根 C 驱动器中,那么这会将其作为系统打开,您可以终止任何进程而不会出现任何拒绝访问错误。将其设置为将来一分钟,然后它会为您弹出。
回答by RmccurdyDOTcom
FYI you can sometimes use SYSTEM or Trustedinstaller to kill tasks ;)
仅供参考,您有时可以使用 SYSTEM 或 Trustedinstaller 来终止任务;)
google quickkill_3_0.bat
谷歌 quickkill_3_0.bat
sc config TrustedInstaller binPath= "cmd /c TASKKILL /F /IM notepad.exe
sc start "TrustedInstaller"
回答by diyism
When ntsd access is denied, try:
当 ntsd 访问被拒绝时,请尝试:
ZeroWave was designed to be a simple tool that will provide a multilevel termination of any kind of process.
ZeroWave 被设计为一个简单的工具,它将为任何类型的过程提供多级终止。
ZeroWave is also a easy-to-use program due to its simple installation and its very friendly graphical interface.
ZeroWave 也是一个易于使用的程序,因为它安装简单,图形界面非常友好。
ZeroWave has three termination modes and with the "INSANE" mode can terminate any kind of process that can run on Windows.
ZeroWave 具有三种终止模式,“INSANE”模式可以终止可以在 Windows 上运行的任何类型的进程。
It seems that ZeroWave can't kill avp.exe
ZeroWave 好像杀不了 avp.exe