如何获得IIS程序池工作进程ID [英] How to get IIS AppPool Worker Process ID

查看:2423
本文介绍了如何获得IIS程序池工作进程ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有当我们的监控服务检测到网站已关闭时自动运行PowerShell脚本。
它应该停止的应用程序池(使用停止-WebAppPool -name $程序池; ),等待,直到它真的停止,然后重新启动

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)"

当您尝试再次启动它。

如果需要更长的时间超过一定秒数停止(我将选择该时间我已超时几个站,看看有多长,通常需要后),我只想杀死进程。

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.

我知道我能得到的使用在程序池的工人做的进程列表 DIR IIS:\\ AppPools \\ MyAppPool \\ WorkerProcesses \\

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

但我无法弄清楚如何真正捕获进程ID,所以我可以杀了它。

but I can't figure out how to actually capture the process id so I can kill it.

推荐答案

在这情况下,进程ID确实是进程的ID杀,您可以:

In case that Process ID is really the id of process to kill, you can:

$id = dir IIS:\AppPools\MyAppPool\WorkerProcesses\ | Select-Object -expand processId
Stop-Process -id $id

dir IIS:\AppPools\MyAppPool\WorkerProcesses\ | % { Stop-Process -id $_.processId }

这篇关于如何获得IIS程序池工作进程ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆