自动Suspend CPU占用率最高进程,夏天CPU好帮手
来源:互联网 发布:freehand for mac 编辑:程序博客网 时间:2024/04/29 15:02
内容如代码所示,温度和suspend、resume策略你需要自己修改一下:
#!/usr/bin/env python# -*- coding=utf-8 -*-import commands, signal, time, os, realarm_temp = 90safe_temp = 70ignore_cpu_percent = 10.0pid_pool = []my_name = ""def resume_one(): global pid_pool if len(pid_pool) == 0: return pid = pid_pool[0] os.kill(pid, signal.SIGCONT) print "Resumed ", pid, " at ", time.strftime('%X %x %Z') pid_pool.remove(pid)def suspend_one(): global pid_pool, myname statue, output = commands.getstatusoutput('ps -eo "%C;%p;%u"') p = re.compile("([0-9\.]+); *?([0-9\.]+);(.*)") m = p.findall(output) if len(m) == 0: return m.sort(lambda a,b: -cmp(float(a[0]),float(b[0]))) for item in m: cpu = float(item[0]) pid = int(item[1]) user = item[2] if user != my_name: continue if cpu <= ignore_cpu_percent: return if pid in pid_pool: continue os.kill(pid, signal.SIGSTOP) print "Suspended", pid, " at ", time.strftime('%X %x %Z') pid_pool.append(pid) time.sleep(10) return def resume_all(): global pid_pool for pid in pid_pool: os.kill(pid, signal.SIGCONT) print "Resumed", pid, " at ", time.strftime('%X %x %Z') pid_pool = []def sigint_handler(signum = 0, e = 0): resume_all() exit(1)def get_temp(): statue, output = commands.getstatusoutput("sensors") p = re.compile("temp1:.*?\+(.*?)°C") m = p.findall(output) if len(m) > 0: return float(m[0]) else: return 0def get_my_name(): global my_name statue, output = commands.getstatusoutput("whoami") my_name = outputif __name__ == '__main__': get_my_name() signal.signal(signal.SIGINT, sigint_handler) while True: temp = get_temp() if temp >= alarm_temp: suspend_one() elif temp <= safe_temp: resume_one() time.sleep(1)
- 自动Suspend CPU占用率最高进程,夏天CPU好帮手
- 获得进程的CPU占用率
- Linux 计算进程CPU占用率
- 获取进程CPU占用率 -- NtQuerySystemInformation
- CPU占用率
- CPU 占用率
- CPU占用率
- 取特定进程的CPU占用率
- 取特定进程的CPU占用率
- solaris下查看进程的cpu占用率
- 如何得到本进程的CPU占用率?
- 如何计算当前进程的CPU占用率
- 系统system进程CPU占用率100%问题
- BES - 控制进程的CPU占用率
- solaris下查看进程的cpu占用率
- JAVA 进程异常高的 CPU 占用率
- 查看进程CPU占用率的方法
- 如何得到本进程的CPU占用率?
- red5 設定 streams 目錄
- CSS优先级
- 1089-1096:A+B for Input-Output Practice
- Iframe自适应高度
- 永不闪烁的C# ListView!
- 自动Suspend CPU占用率最高进程,夏天CPU好帮手
- 仿百度文库解决方案(一) - 总体思路
- 实训总结-3g-王帅
- spring3.0事务的多数据源的annotation-driven用法
- nyoj 356 Jumping Cows
- 建立openstack quantum开发环境 .
- Serializable和Parcelable实现序列化
- 仿百度文库解决方案(三)- 利用JODConverter把文档转换成pdf格式
- iOS 数据持久性存储--属性列表存储