python读取和结束进程
read and kill process in pythonread the process in your linux systemimport ostmp = os.popen("ps -af").read()#读取系统上所有的进程gzclient_count = tmp.count('gzclient')#常看是否有cmd为'gzclient'的进程,如果有,则值为
·
read and kill process in python
- read the process in your linux system
import os
tmp = os.popen("ps -af").read()
#读取系统上所有的进程
gzclient_count = tmp.count('gzclient')
#常看是否有cmd为'gzclient'的进程,如果有,则值为1,否则为0
# The -a option tells ps to list the processes of all users on the system rather than just those of the current user.
#The -f option generates a listing that contains fewer items of information for each process than the -l option.
- kill the process
if gzclient_count > 0:
#如果有正在运行的gaclient进程
os.system("killall -9 gzclient")
#结束所有的gzclient进程
更多推荐
已为社区贡献1条内容
所有评论(0)