Difference between taskkill and taskkill /f

我与影子孤独终老i 提交于 2019-12-10 03:45:21

问题


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

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

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


回答1:


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.

You can try following experiments:

  1. Launch notepad.exe and type a few chars in the notpad window
  2. Type taskkill /f /im notepad.exe. Notepad will quit immediately

Now do this:

  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.


来源:https://stackoverflow.com/questions/32346219/difference-between-taskkill-and-taskkill-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!