實驗:將系統程式對映移到 Python 字典中
參考官方文件,測試下列程式碼,把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'},
.................................
[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'},
.................................
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29135257/viewspace-2123401/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 如何高效地將SQL資料對映到NoSQL儲存系統中SQL
- Win10系統將OneDrive對映到本地的方法Win10
- Python 將所有 Bug 遷移到 GitHub 中PythonGithub
- 打造強大的BaseModel(2):讓Model實現自動對映,將字典轉化成Model
- 使用RAM將檔案系統遷移到ASMASM
- 將資料庫遷移到ASM的實驗記錄資料庫ASM
- Python將字串轉為字典最佳實踐Python字串
- 對系統快捷生成字典進行修改
- 將ServiceLoader遷移到Java 9模組系統 - frankelJava
- 將spfile從ASM裡遷移到檔案系統ASM
- python實現兩字串對映詳解Python字串
- 學習將車輛對映到鳥瞰圖中:幫助駕駛系統全面理解道路場景
- java高階用法之:在JNA中將本地方法對映到JAVA程式碼中Java
- 作業系統實驗——程式控制作業系統
- 如何將csf ip 埠對映
- 一文讀懂Python中的對映Python
- [PY3]——合併多個字典或對映(collections模組中的ChainMap 類)AI
- python 關係對映Python
- ElasticSearch中的對映Elasticsearch
- 將 CentOS 8 作業系統遷移到 Oracle LinuxCentOS作業系統OracleLinux
- 將資料庫從ASM遷移到檔案系統資料庫ASM
- 將資料庫從檔案系統遷移到ASM資料庫ASM
- Python中的字典Python
- 作業系統實驗2 程式控制和系統呼叫作業系統
- Python 決定放棄 BPO,將所有 Bug 遷移到 GitHub 中PythonGithub
- python怎麼對字典排序Python排序
- Python對字典進行排序Python排序
- mybatis中註解對映SQL示例程式碼MyBatisSQL
- 實現資料庫由檔案系統遷移到 ASM 磁碟組中資料庫ASM
- Windows是如何將64位Ntdll對映到32位程式的Windows
- iptables 實現埠對映
- Python中遍歷字典以及字典中的鍵和值Python
- 如何將物理機Windows系統遷移到VMware虛擬機器?Windows虛擬機
- 利用RMAN將資料庫從檔案系統遷移到ASM資料庫ASM
- 埠對映,內網網站對映外網訪問,透過80埠對映實現內網網站
- 將json資料轉換為Python字典將json資料轉換為Python字典JSONPython
- 如何在win10系統中對映網路驅動器_win10電腦對映網路驅動器的方法Win10
- Python實現建立字典Python