简体   繁体   English

在PowerShell中终止进程

[英]Kill process in PowerShell

I tried to kill process from PowerShell by Stop-Service -Name (service name) . 我试图通过Stop-Service -Name (service name)杀死PowerShell中的进程。 Sometimes the process exits properly, but sometimes even though the service gets stopped the background Java process for this app doesn't stop. 有时,该进程会正确退出,但有时,即使服务已停止,此应用程序的后台Java进程也不会停止。 Is there a solution to stop Java if it hasn't from PowerShell. 如果没有从PowerShell中停止Java,是否有解决方案来停止它。 The problem is that we have to find the right Java process and kill only that as we have other Java processes also running. 问题在于,我们必须找到正确的Java进程并杀死它,因为我们还要运行其他Java进程。

Stop-Service doesn't kill a process. Stop-Service不会Stop-Service进程。 It makes a request to the service control manager (SCM) to ask it to stop a service with a particular name. 它向服务控制管理器 (SCM)发出请求,要求它停止具有特定名称的服务。 The SCM will then call into the process hosting the service and ask it to stop. 然后,SCM将调用托管该服务的进程,并要求其停止。

It's possible that the service won't shut down correctly when asked, and the SCM will timeout the call to stop the service. 当被询问时,该服务可能无法正确关闭,并且SCM将使呼叫超时以停止该服务。 This tends to lead to the service showing as stopped in the SCM but still running in the background, which is what you are seeing. 这往往导致服务显示为已在SCM中停止,但仍在后台运行,这就是您所看到的。

If you want to explicitly kill the process hosting the service then you'll need to find a way to map the service name to a process id. 如果要显式终止托管服务的进程,则需要找到一种将服务名称映射到进程ID的方法。 This question may help you. 这个问题可能对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM