参考官方文档,测试下列代码,把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. 118th LeetCode Weekly Contest Powerful Integers

    Given two non-negative integers x and y, an integer is powerful if it is equal to x^i + y^j for some ...

  2. 使用JDBC连接了数据库的图书管理系统2.0

    更新日志: 2019.3.28 数据库版本2.0 1.使用mySQL数据库 2.修改代码使用JDBC连接数据库 3.新增Manage操作类及DBUtils数据库工具类 4.完善代码(封装及方法调用) ...

  3. Python+Selenium定位元素的方法

    Python+Selenium有以下八种定位元素的方法: 1. find_element_by_id() eg: find_element_by_id("kw") 2. find_ ...

  4. 【C#】隐式类型var

    在.NET 3.0后微软引入了隐式类型var,编译器可以自动判断变量的类型,通过var这个隐式类型,可以提高开发人员的开发效率,很多时候可以不考虑对象的类型,编译器会自动帮我们判断 使用隐式类型和使用 ...

  5. Beam概念学习系列之Pipeline 数据处理流水线

    不多说,直接上干货! Pipeline 数据处理流水线 Pipeline将Source PCollection ParDo.Sink组织在一起形成了一个完整的数据处理的过程. Beam概念学习系列之P ...

  6. 8086实时时钟实验(一)——《x86汇编语言:从实模式到保护模式》05

    1.代码清单 ;代码清单9-1 ;文件名:c09_1.asm ;文件说明:用户程序 ;创建日期:2011-4-16 22:03 ;=================================== ...

  7. 项目管理系统 TAIGA 部署

    题记 使用了 MantisBT 一段时间,觉得功能太少,只局限在错误跟踪,而且操作体验比较差,界面很糟糕,很早就想将其换掉. 偶然发现一个很不错的新选择:Taiga,于是就试着将其部署下来,发现绝对是 ...

  8. php自建静态博客步骤

    进入博客目录新建index.php页面 <?php require “XXXX/index.html”;//引入html页面 是否能进入localhost/xxx/index.php 注意,ph ...

  9. rest-framework框架——视图三部曲

    一.mixins类编写视图 1.配置url urlpatterns = [ ... re_path(r'^authors/$', views.AuthorView.as_view(), name=&q ...

  10. shell 复制/备份文件 脚本

    #!/bin/sh # author hapday # -- echo "以时间日期为名称基准备份 war 包." date +%Y-%m-%d-%H-%M-%S cp artup ...