python自动kill掉长时间的S类php进程(centos7.0)

该Python脚本用于查找并终止在CentOS7.0系统上运行超过6小时的S状态PHP进程。通过`ps`命令筛选出符合条件的PID,再获取其启动时间,计算运行时长,最后执行`kill`命令终止进程。
摘要由CSDN通过智能技术生成
import os
import time
import datetime

month_arr ={'Jan':1, 'Feb':2, 'Mar':3, 'Apr':4, 'May':5, 'Jun':6, 'Jul':7, 'Aug':8, 'Sep':9, 'Oct':10, 'Nov':11, 'Dec':12}
#os.system('kill -9 2383')
output = os.popen("ps aux | grep S|awk '{print $2,$11,$12}'").read().split('\n')
for command_line in output:
        com_arr = command_line.split(' ')
        if(len(com_arr)==3 and com_arr[0].isdigit()):
                #print(com_arr);
                pid_str = com_arr[0]
                com_str = "ps -p " + pid_str + " -o lstart | grep -v \"START\""
                #print(com_str)
                pid_start_time = os.popen(com_str).read()
                pid_time_arr = pid_start_ti
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值