新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
創(chuàng)新互聯(lián)Python教程:Python如何判斷程序是否運(yùn)行
本篇文章介紹了python判斷程序進(jìn)程是否存在的方法,希望對(duì)學(xué)習(xí)Python的朋友有幫助!

網(wǎng)站的建設(shè)成都創(chuàng)新互聯(lián)專注網(wǎng)站定制,經(jīng)驗(yàn)豐富,不做模板,主營(yíng)網(wǎng)站定制開(kāi)發(fā).小程序定制開(kāi)發(fā),H5頁(yè)面制作!給你煥然一新的設(shè)計(jì)體驗(yàn)!已為成都廣告設(shè)計(jì)等企業(yè)提供專業(yè)服務(wù)。
Python如何判斷程序是否運(yùn)行
1、進(jìn)程名
import psutil
def judgeprocess(processname):
pl = psutil.pids()
for pid in pl:
if psutil.Process(pid).name() == processname:
print(pid)
break
else:
print("not found")
if judgeprocess('notepad++.exe') == 0:
print('success')
else:
pass2、進(jìn)程ID
import errno
import os
import sys
def pid_exists(pid):
"""Check whether pid exists in the current process table.
UNIX only.
"""
if pid < 0:
return False
if pid == 0:
# According to "man 2 kill" PID 0 refers to every process
# in the process group of the calling process.
# On certain systems 0 is a valid PID but we have no way
# to know that in a portable fashion.
raise ValueError('invalid PID 0')
try:
os.kill(pid, 0)
except OSError as err:
if err.errno == errno.ESRCH:
# ESRCH == No such process
return False
elif err.errno == errno.EPERM:
# EPERM clearly means there's a process to deny access to
return True
else:
# According to "man 2 kill" possible error values are
# (EINVAL, EPERM, ESRCH)
raise
else:
return True推薦學(xué)習(xí)《Python教程》。
網(wǎng)頁(yè)題目:創(chuàng)新互聯(lián)Python教程:Python如何判斷程序是否運(yùn)行
網(wǎng)頁(yè)鏈接:http://www.dlmjj.cn/article/djieddd.html


咨詢
建站咨詢
