taskkill 和 taskkill/f 的区别 [英] Difference between taskkill and taskkill /f

查看:101
本文介绍了taskkill 和 taskkill/f 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Microsoft Technet 上,我可以阅读 taskkill 有一个 /f 参数来强制终止进程.我想知道这在内部做了什么,以了解此类操作的影响.

On Microsoft Technet I can read that taskkill has a /f parameter to kill a process forcefully. I wonder what this does internally, to understand the impact of such an action.

taskkill(没有 /f)不会简单地向进程发送 WM_CLOSE 消息,否则我的应用程序会询问是否保存打开的文档.这让我假设它已经在 TerminateProcess (MSDN) 级别.但是,TerminateProcess 没有用于强制终止的参数.

taskkill (without /f) does not simply send a WM_CLOSE message to the process, otherwise my application would ask whether or not to save the open documents. This makes me assume that it already operates on a TerminateProcess (MSDN) level. However, TerminateProcess does not have a parameter for forcing a kill.

那么,taskkilltaskkill/f 在内部做了什么?

So, what do taskkill and taskkill /f do internally?

我阅读了相关问题 C# Process.Kill() 和 Taskkill 的区别 但它没有答案.

I read the related question Difference between C# Process.Kill() and Taskkill but it does not have an answer.

推荐答案

最有可能的 taskkill/f 使用 TerminateProcess,其中 taskkill 没有 /f 只是发布一个 WM_QUIT 消息(不是 WM_CLOSE).文档说 TerminateProcess 无条件地终止进程.

Most likely taskkill /f uses TerminateProcess, where as taskkill without /f just posts a WM_QUIT message (not WM_CLOSE). The docs says that TerminateProcess unconditionally kills the process.

您可以尝试以下实验:

  1. 启动 notepad.exe 并在记事本窗口中输入几个字符
  2. 输入 taskkill/f/im notepad.exe.记事本将立即退出
  1. Launch notepad.exe and type a few chars in the notpad window
  2. Type taskkill /f /im notepad.exe. Notepad will quit immediately

现在这样做:

  1. 启动 notepad.exe 并在记事本窗口中输入几个字符
  2. 输入taskkill/im notepad.exe.记事本不会立即退出,但会退出询问您是否要保存修改.
  1. Launch notepad.exe and type a few chars in the notpad window
  2. Type taskkill /im notepad.exe. Notepad won't quit immediately but it will quit ask if you want to save modifiactions.

这篇关于taskkill 和 taskkill/f 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆