我正在编写一个python脚本,以保持有问题的程序打开,我需要弄清楚该程序是否没有重新安装并在Windows上将其关闭.我不太清楚该怎么做.解决方法:在Windows上,您可以执行以下操作:import osdef isresponding(name):os....

我正在编写一个python脚本,以保持有问题的程序打开,我需要弄清楚该程序是否没有重新安装并在Windows上将其关闭.我不太清楚该怎么做.
解决方法:
在Windows上,您可以执行以下操作:
import os
def isresponding(name):
os.system('tasklist /FI "IMAGENAME eq %s" /FI "STATUS eq running" > tmp.txt' % name)
tmp = open('tmp.txt', 'r')
a = tmp.readlines()
tmp.close()
if a[-1].split()[0] == name:
return True
else:
return False
但是,使用PID更可靠:
def isrespondingPID(PID):
os.system('tasklist /FI "PID eq %d" /FI "STATUS eq running" > tmp.txt' % PID)
tmp = open('tmp.txt', 'r')
a = tmp.readlines()
tmp.close()
if int(a[-1].split()[1]) == PID:
return True
else:
return False
从任务列表中,您可以获得更多信息.要直接获得“不响应”过程,只需在给定的功能中通过“不响应”来更改“运行”. See more info here.
沃梦达教程
本文标题为:如何判断进程是否在Windows上的Python中响应


基础教程推荐
猜你喜欢
- 基于Python实现简易的植物识别小系统 2023-08-04
- python time模块计算时间之间的差距(练习题) 2023-08-04
- 在Nginx下运行python 2023-11-12
- 在Windows Server 2012上如何处理“ OverflowError:Python int太大而无法转换为C long”错误,如何获得转换? 2023-11-11
- 浅谈Django Admin的初步使用 2023-08-09
- 用了python多进程,我跑程序花费的时间缩短了4倍 2023-09-04
- [Python] Unofficial Windows Binaries for Python Extension Packages 2023-11-12
- python使用fork实现守护进程的方法 2023-09-03
- 在python中将数组存储到持久内存的有效方法 2023-11-11
- 基于Python Dash库制作酷炫的可视化大屏 2023-08-04