如何获取 IIS AppPool 工作进程 ID
我有一个 PowerShell 脚本,当我们的监控服务检测到网站关闭时,该脚本会自动运行。 它应该停止AppPool(使用Stop-WebAppPool -name $AppPool;
),等到它真正停止然后重新启动它。
有时,该进程实际上并未停止,
Cannot Start Application Pool:
The service cannot accept control messages at this time.
(Exception from HRESULT: 0x80070425)"
当您尝试再次启动它时会出现错误。
如果停止时间超过一定秒数(我会在多次停止计时后选择该时间量,看看通常需要多长时间),我想终止该进程。
我知道我可以通过执行 dir IIS:\AppPools\MyAppPool\WorkerProcesses\
来获取 AppPool 中工作人员使用的进程列表,
Process ID State Handles Start Time
---------- ----- ------- ----------
7124 Running
但我不知道如何实际捕获进程 id这样我就可以杀死它。
I have a PowerShell script that is run automatically when our monitoring service detects that a website is down.
It is supposed to stop the AppPool (using Stop-WebAppPool -name $AppPool;
), wait until it is really stopped and then restart it.
Sometimes it the process does not actually stop, manifested by the error
Cannot Start Application Pool:
The service cannot accept control messages at this time.
(Exception from HRESULT: 0x80070425)"
when you try to start it again.
If it takes longer than a certain number of seconds to stop (I will chose that amount of time after I have timed several stops to see how long it usually takes), I want to just kill the process.
I know that I can get the list of processes used by workers in the AppPool by doing dir IIS:\AppPools\MyAppPool\WorkerProcesses\
,
Process ID State Handles Start Time
---------- ----- ------- ----------
7124 Running
but I can't figure out how to actually capture the process id so I can kill it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果进程 ID 确实是要杀死的进程的 ID,您可以:
或
In case that Process ID is really the id of process to kill, you can:
or
在服务器上的命令提示符中,我只需对正在运行的 AppPool PID 列表执行以下操作,以便我可以使用 taskkill 或 Task Mgr 杀死它们:
In Command Prompt on the server, I just do the following for a list of running AppPool PIDs so I can kill them with taskkill or Task Mgr:
(添加 Roman 评论中的答案,因为 stej 的解决方案可能存在缓存问题)
在 Web 服务器上以管理员身份打开 Powershell,然后运行:
您应该看到类似以下内容:
然后您可以使用任务管理器来终止它或在 Powershell 中使用:
如果您得到 Get-WmiObject : 无法从命名空间 root/WebAdministration 获取对象。命名空间无效,那么您需要使用以下命令启用IIS 管理脚本和工具功能:
(Adding answer from Roman's comment, since there maybe cache issues with stej's solution)
Open Powershell as an Administrator on the web server, then run:
You should see something like:
You can then use Task Manager to kill it or in Powershell use:
If you get Get-WmiObject : Could not get objects from namespace root/WebAdministration. Invalid namespace then you need to enable the IIS Management Scripts and Tools feature using:
我也遇到了同样的问题,这是我的解决方案:
I also had the same problem, and here is my solution: