PowerShell 不会终止挂起的进程 [英] PowerShell won't terminate hung process
问题描述
我有一个场景,由于 Oracle 数据库,每个星期一早上都有一个进程被卡住,所以我尝试创建一个 PowerShell 脚本以在每个星期一运行,但无论是否出现错误,该进程仍然存在.
I have a scenario where a process is stuck every single Monday morning because of an Oracle database so I tried creating a PowerShell script to run every Monday but regardless of getting an error or not, the process remains.
我试图用于杀死"的行是:
The line I'm attempting to use for the "kill" is:
Get-Process -Name ez0* -ComputerName $server | Stop-Process -Force
尝试在没有 -ComputerName
的情况下在本地执行此操作.
Tried doing this locally as well without the -ComputerName
.
无论是否使用 -Force
,我都不会从这一行收到任何错误,它只是执行并继续前进.
I'm not getting any errors from this line with or without the -Force
it just executes and moves on.
只是执行 Get-Process
工作,我可以看到它,但我不能用 PowerShell 结束它.经过多次尝试,我远程登录到服务器并右键单击该进程并选择结束任务",效果很好.
Just doing Get-Process
works and I can see it but I can't end it with PowerShell. After many attempts I remotely logged on to the server and just right-clicked the process and chose "End task" which worked just fine.
这是一个奇怪的进程,因为它是初始 8 个进程中的一个(基于内核),当您停止服务时,除了挂起的进程之外,所有进程都被删除.
It is an odd process because it's one out of initial 8 (based on cores) and when you stop the service, all but one of the processes is removed save for the one that is hung.
推荐答案
尝试使用:
$termproc = (get-wmiobject -ComputerName $server -Class Win32_Process -Filter "name like 'ez0%'"
$termproc.terminate()
如果您不想先检查变量中的进程,也可以执行以下操作.
You could also just do the below if you don't want to check the processes in the variable first.
(get-wmiobject -ComputerName $server -Class Win32_Process -Filter "name like 'ez0%'").terminate()
谢谢,蒂姆.
这篇关于PowerShell 不会终止挂起的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!