实验:将系统进程映射移到 Python 字典中
[oracle@ycr python]$ more pro_get.py
import re
import subprocess
args = ['ps', 'aux']
ps = subprocess.Popen(args, stdout=subprocess.PIPE)
processes = ps.stdout.readlines()
header = re.split('\s+', processes.pop(0))[:-1]
header.remove('COMMAND')
PS = {}
for process in processes:
columns = re.split('\s+', process)
if columns[0]!='oracle':
continue
PS[int(columns[1])] = {}
for position, column in enumerate(columns[:9]):
PS[int(columns[1])][header[position].lower()] = column
PS[int(columns[1])]['command'] = ' '.join(columns[10:])
from pprint import pprint
pprint(PS)
输出结果如下:
[oracle@ycr python]$ python pro_get.py
{2564: {'%cpu': '0.0',
'%mem': '1.4',
'command': 'ora_pmon_ycr ',
'pid': '2564',
'rss': '27276',
'start': '04:09',
'stat': 'Ss',
'tty': '?',
'user': 'oracle',
'vsz': '1089560'},
2566: {'%cpu': '0.0',
'%mem': '1.0',
'command': 'ora_psp0_ycr ',
'pid': '2566',
'rss': '20112',
'start': '04:09',
'stat': 'Ss',
'tty': '?',
'user': 'oracle',
'vsz': '1089560'},
2568: {'%cpu': '1.9',
'%mem': '1.0',
'command': 'ora_vktm_ycr ',
'pid': '2568',
'rss': '19724',
'start': '04:09',
'stat': 'Ss',
'tty': '?',
'user': 'oracle',
'vsz': '1089560'},
2572: {'%cpu': '0.0',
'%mem': '1.7',
'command': 'ora_gen0_ycr ',
'pid': '2572',
'rss': '34032',
'start': '04:09',
'stat': 'Ss',
'tty': '?',
'user': 'oracle',
'vsz': '1091300'},
.................................
实验:将系统进程映射移到 Python 字典中的更多相关文章
- python字典中的元素类型
python字典默认的是string item={"browser " : 'webdriver.irefox()', 'url' : 'http://xxx.com'} 如果这样 ...
- 判断python字典中key是否存在的两种方法
今天来说一下如何判断字典中是否存在某个key,一般有两种通用做法,下面为大家来分别讲解一下: 第一种方法:使用自带函数实现. 在python的字典的属性方法里面有一个has_key()方法,这个方法使 ...
- python字典中添加项
body_daily_close = { "mappings": { "properties": { "trade_date": { &qu ...
- 十四、python字典中的方法汇总
'''1.访问.修改,删除字典中的值:''' dict={'a':'11','b':'22','c':'33','d':'44'}print dict['a'],dict['d'] #访问dict[' ...
- 【python-字典】判断python字典中key是否存在的
一般有两种通用做法: 第一种方法:使用自带函数实现: 在python的字典的属性方法里面有一个has_key()方法: #生成一个字典 d = {'name':Tom, 'age':10, 'Tel' ...
- Python 字典中一键对应多个值
#字典的一键多值 print'方案一 list作为dict的值 值允许重复' d1={} key=1 value=2 d1.setdefault(key,[]).append(value) value ...
- python 字典中 重复值去除
tuple_r_dict = lambda _dict: dict(val[::-1] for val in _dict.items()) # Python3.x tuple_r_dict(tuple ...
- Python字典中的值为列表或字典的构造方法
转自: https://blog.csdn.net/buside/article/details/81323871 1.值为列表的构造方法 dic = {} dic.setdefault(key,[] ...
- python字典中dict.get()和dict.setdefault()的异同点
相同点: 两者是参数相同:dict.get(key, default=None), dict.setdefault(key, default=None) 如果指定的键不存在时,两者都返回默认值,默认是 ...
随机推荐
- webstorm识别 ftl文件
webstorm对freemaker语法是原生支持的,也不需要安装什么插件,你可以直接在webstorm新建个File Types即可 file->settings->file types ...
- [转] 商业应用中Java浮点数的精确计算及表示
[From] https://blog.csdn.net/stevene/article/details/586089 问题提出 (1).浮点数精确计算 胜利油田三流合一项目中一直存在一个问题,就是每 ...
- Axis 生成客户端client stub文件
[转自] http://blog.csdn.net/qiao000_000/article/details/5568442 开发前,有个同事先给我们不熟悉Web Service的程序员进行了一些培训, ...
- Oracle之AUTHID CURRENT_USER
没有AUTHID CURRENT_USER表示定义者权限(definer rights),以定义者身份执行: 加上AUTHID CURRENT_USER表示调用者权限(invoker rights), ...
- centos 7更新yum源与更新系统
1.备份/etc/yum.repos.d/下的原有文件(假如你想保留原系统的yum源的话),举例 cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos ...
- Python入门笔记——(1)数字与表达式
一.算术运算 整除:// 取余:% 乘方:** (a ** b = pow(a, b)) 十六进制表示:0x...,八进制表示0... round(x [, n]):对x从小数点第n位取四舍五入结果, ...
- Python(xlrd、xlwt模块)操作Excel实例(一)
一.前言 关于Python的xlrd.xlwt模块的使用,推介另一位博客主的博文:https://www.cnblogs.com/zhoujie/p/python18.html 这篇里面有详细介绍这两 ...
- Reading a IMU Without Kalman: The Complementary Filter
目标是将惯性测量元件(IMU)之中陀螺仪.加速计的数据结合使用.Kalman filter太复杂,在微机上倾向用一种更简单的方法:Complementary filter 姿态估计(获得3个角度,俯仰 ...
- Oracle broker--详解
1,简介 01,介绍 Data Guard broker是建立在Data Guard基础上的一个对Data Guard配置,集中管理操作的一个平台.我们再上次DG主备切换的时候会发现特别麻烦,为此br ...
- lnmp 优化
一,版本信息优化 重启 直接更改版本号: 在源码包里改 第二个要改的地方 第三个需要更改的 改完后编译安装,下次我直接写进编译脚本上