简体   繁体   English

Python:如何监视Windows Scheduler中运行的多个Python进程的状态

[英]Python: How to monitor status of multiple Python processes running in Windows Scheduler

I have several Python modules running under the Windows Scheduler (Windows Server 2008 R2). 我有几个在Windows Scheduler(Windows Server 2008 R2)下运行的Python模块。 I'd like to verify that they are active ('running') and haven't been inadvertently stopped. 我想验证它们是否处于活动状态(“正在运行”)并且没有意外停止。

 os.popen("tasklist").read()

Only tells me there are Python processes, it doesn't give me their status (running/ready/etc) or a way to ID which process it is. 只告诉我有Python进程,它没有告诉我它们的状态(运行/就绪/等),也没有告诉我它是哪个进程的方法。

Can someone assist, please? 有人可以帮忙吗?

You can use Windows Management Instrumentation : a package in python to work with windows processes and other information. 您可以使用Windows Management Instrumentation :python中的一个软件包,用于处理Windows进程和其他信息。 You can find some example here . 您可以在此处找到一些示例。

In your case you can do: 在您的情况下,您可以执行以下操作:

import wmi
c = wmi.WMI ()

for process in c.Win32_Process ():
    print process.ProcessId, process.Name, process.Status

The list of all properties of Win32_Process is here on Microsoft website. Win32_Process的所有属性的列表, 在这里微软网站。

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

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