参考官方文档,测试下列代码,把oracle的进程映射到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 字典中的更多相关文章

  1. python字典中的元素类型

    python字典默认的是string item={"browser " : 'webdriver.irefox()', 'url' : 'http://xxx.com'} 如果这样 ...

  2. 判断python字典中key是否存在的两种方法

    今天来说一下如何判断字典中是否存在某个key,一般有两种通用做法,下面为大家来分别讲解一下: 第一种方法:使用自带函数实现. 在python的字典的属性方法里面有一个has_key()方法,这个方法使 ...

  3. python字典中添加项

    body_daily_close = { "mappings": { "properties": { "trade_date": { &qu ...

  4. 十四、python字典中的方法汇总

    '''1.访问.修改,删除字典中的值:''' dict={'a':'11','b':'22','c':'33','d':'44'}print dict['a'],dict['d'] #访问dict[' ...

  5. 【python-字典】判断python字典中key是否存在的

    一般有两种通用做法: 第一种方法:使用自带函数实现: 在python的字典的属性方法里面有一个has_key()方法: #生成一个字典 d = {'name':Tom, 'age':10, 'Tel' ...

  6. Python 字典中一键对应多个值

    #字典的一键多值 print'方案一 list作为dict的值 值允许重复' d1={} key=1 value=2 d1.setdefault(key,[]).append(value) value ...

  7. python 字典中 重复值去除

    tuple_r_dict = lambda _dict: dict(val[::-1] for val in _dict.items()) # Python3.x tuple_r_dict(tuple ...

  8. Python字典中的值为列表或字典的构造方法

    转自: https://blog.csdn.net/buside/article/details/81323871 1.值为列表的构造方法 dic = {} dic.setdefault(key,[] ...

  9. python字典中dict.get()和dict.setdefault()的异同点

    相同点: 两者是参数相同:dict.get(key, default=None), dict.setdefault(key, default=None) 如果指定的键不存在时,两者都返回默认值,默认是 ...

随机推荐

  1. tomcat普通用户启动不了

    Neither the JAVA_HOME nor the JRE_HOME environment variable is defined  At least one of these enviro ...

  2. html自定义垂直导航菜单(多级导航菜单,去掉font-awesome图标,添加自己的箭头图标)

    这次在原先html自定义垂直导航菜单的基础上做了比较大的改动: 1.去掉了font-awesome图标,上级菜单右边的箭头是自己用css写的,具体参考<css三角箭头>. 2.去掉了初始化 ...

  3. Android应用中添加Log4j的示例

    [2016-06-30]最新的log4j已经集成在DR_support_lib库中 具体请看: https://coding.net/u/wrcold520/p/DR_support_lib/git/ ...

  4. C语言两种方式实现矩阵的转置

    #include"stdio.h" typedef struct{ int i,j; int v; }Triple; typedef struct{ Triple date[]; ...

  5. Spring Cloud Zuul实现动态路由

    1.添加依赖 2.启动类上添加注解 3.配置文件 zuul.ignored-services配置需要忽略的服务,多个用逗号分隔 注释zuul.ignored-services 前: 注释zuul.ig ...

  6. NPM, BOWER, GIT, AND BASH PROXY CONFIGURATIONS

    Sources: http://digitaldrummerj.me/proxy-configurations/ When you are using npm, bower, and git behi ...

  7. 案例40-层与层之间的解耦(面向接口编程)BeanFactory

    1 bean.xml配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans> <!- ...

  8. 【数据结构】最小生成树之prim算法和kruskal算法

    在日常生活中解决问题经常需要考虑最优的问题,而最小生成树就是其中的一种.看了很多博客,先总结如下,只需要您20分钟的时间,就能完全理解. 比如:有四个村庄要修四条路,让村子能两两联系起来,这时就有最优 ...

  9. Coursera 机器学习 第8章(上) Unsupervised Learning 学习笔记

    8 Unsupervised Learning8.1 Clustering8.1.1 Unsupervised Learning: Introduction集群(聚类)的概念.什么是无监督学习:对于无 ...

  10. nyoj 1197——你会加吗?——————【快速幂、分治】

    你会加吗? 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 给出两个整数A和N,计算(A + A^2 + A^3 + …… + A^(N - 1) + A^N)% 6 ...