我想杀死一个进程:
$ ps Sourcetree
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
1311 116 136720 137804 57.45 1044 1 SourceTree
Stop-Process
,又名kill
:
$ ps Sourcetree | kill
运行无错误。但进程并没有被终止:
$ ps Sourcetree
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
1311 116 136720 137804 57.45 1044 1 SourceTree
如何使用powershell强行杀死进程?
使用
-Force
。
ps -force Sourcetree | kill
Stop-Process [-Id] <Int32[]> [-PassThru] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
-Force
Stops the specified processes without prompting for confirmation.
By default, Stop-Process prompts for confirmation before stopping
any process that is not owned by the current user.
To find the owner of a process, use the Get-WmiObject cmdlet to
get a Win32_Process object that represents the process, and then
use the GetOwner method of the object.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
额外的玉米片,
Get-Command -ParameterName *force
将显示包含 force 参数的所有 Cmdlet。
如果你这么做了?
(get-process -Name SourceTree).Kill()
为了更好地理解 cmdlet 及其功能,您可以随时执行
Get-Help cmdlet
并查看它的功能\支持。
Get-Help Stop-Process
或者只需在搜索引擎中输入 cmdlet,这很可能会引导您找到官方帮助文章。
最简单的正确答案是:
Get-Process SourceTree | Stop-Process -Force
“SourceTree”是进程名称。