3
×{MeÊ� ã @ s¾ d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm Z dZ
dd„ Zdd „ ZG d
d„ dƒZ
dd
„ Zdd„ ZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG d d!„ d!ƒZG d"d#„ d#ƒZed$k�rºd dlZeƒ Zx0eejjƒ ƒD ]Ze e› d%eje › �ƒ �q*W eƒ Z!x0ee!j!jƒ ƒD ]Z"e e"› d%e!j!e" › �ƒ �qbW eƒ Z#e d&e#j$› d'�ƒ x,ee#jƒ ƒD ]Z%e e%› d(e#e% › �ƒ �qªW e d)d*d+ ƒ ee&ej'd, ƒƒZ(x8ee(j)ƒD ]*Ze e(j*e j+d-›d.e(j*e j,› �ƒ �qøW e d*d+ ƒ x&e(j-ej'd/ ƒD ]Z.e e.d0 ƒ �qDW eƒ Z/e e/d, ƒ eƒ Z0xFej1d,ƒ e0j2ƒ x$e0D ]Z#e e#› d%e0e# › �ƒ �qŒW e d2ƒ �qtW dS )3é N)Úreduce)Úrange)Úbitmasklistz0.7.3c C s t jƒ } ttjd| ƒƒS )z) Return True if running on s390 or s390x Zs390)ÚplatformÚmachineÚboolÚreÚsearch)r © r
ú/usr/lib/python3.6/procfs.pyÚis_s390 s r c C s: | d rt dd„ | d ƒjƒ S y| d d S dS dS )z¶
Returns the process command line, if available in the given `process' class,
if not available, falls back to using the comm (short process name) in its
pidstat key.
Úcmdlinec S s | d| S )Nz %sr
)ÚaÚbr
r
r Ú! s z!process_cmdline..ÚstatÚcommN)r Ústrip)Zpid_infor
r
r Úprocess_cmdline s r c + @ sN e Zd ZdZdZdZdZdZdZdZ dZ
d Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$d Z%d!Z&d!Z'd"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dd?d@dAdBdCdDdEdFdGdHdIdJdKdLg+Z(dcdNdO„Z)dPdQ„ Z*dRdS„ Z+dTdU„ Z,dVdW„ Z-dXdY„ Z.dZd[„ Z/ddd\d]„Z0d^d_„ Z1d`da„ Z2dbS )eÚpidstatam
Provides a dictionary to access the fields in the
per process /proc/PID/stat files.
One can obtain the available fields by asking for the keys of the
dictionary, e.g.:
>>> p = procfs.pidstat(1)
>>> print p.keys()
['majflt', 'rss', 'cnswap', 'cstime', 'pid', 'session', 'startstack', 'startcode', 'cmajflt', 'blocked', 'exit_signal', 'minflt', 'nswap', 'environ', 'priority', 'state', 'delayacct_blkio_ticks', 'policy', 'rt_priority', 'ppid', 'nice', 'cutime', 'endcode', 'wchan', 'num_threads', 'sigcatch', 'comm', 'stime', 'sigignore', 'tty_nr', 'kstkeip', 'utime', 'tpgid', 'itrealvalue', 'kstkesp', 'rlim', 'signal', 'pgrp', 'flags', 'starttime', 'cminflt', 'vsize', 'processor']
And then access the various process properties using it as a dictionary:
>>> print p['comm']
systemd
>>> print p['priority']
20
>>> print p['state']
S
Please refer to the 'procfs(5)' man page, by using:
$ man 5 procfs
To see information for each of the above fields, it is part of the
'man-pages' RPM package.
é é é é é é é@ é€ é i i i i i i @ i € i i i i i i i @ i € i i i i i i i @l Úpidr ÚstateZppidZpgrpZsessionZtty_nrZtpgidÚflagsZminfltZcminfltZmajfltZcmajfltÚutimeZstimeZcutimeZcstimeZpriorityÚniceZnum_threadsZitrealvalueZ starttimeZvsizeZrssZrlimZ startcodeZendcodeZ
startstackZkstkespZkstkeipÚsignalZblockedZ sigignoreZsigcatchZwchanZnswapZcnswapZexit_signalÚ processorÚrt_priorityZpolicyZdelayacct_blkio_ticksÚenvironú/procc C s0 || _ y| j|ƒ W n tk
r* ‚ Y nX d S )N)r ÚloadÚFileNotFoundError)Úselfr Úbasedirr
r
r Ú__init__~ s
zpidstat.__init__c C s
| j | S )N)Úfields)r+ Ú fieldnamer
r
r Ú__getitem__‡ s zpidstat.__getitem__c C s t | jjƒ ƒS )N)Úlistr. Úkeys)r+ r
r
r r2 Š s zpidstat.keysc C s t | jjƒ ƒS )N)r1 r. Úvalues)r+ r
r
r r3 � s zpidstat.valuesc C s
|| j kS )N)r. )r+ r/ r
r
r Úhas_key� s zpidstat.has_keyc C s | j S )N)r. )r+ r
r
r Úitems“ s z
pidstat.itemsc C s
|| j kS )N)r. )r+ r/ r
r
r Ú__contains__– s zpidstat.__contains__c C sì yt |› d| j› d�ƒ}W n tk
r0 ‚ Y nX |jƒ jƒ jdƒ}|jƒ |d jdƒ|d jƒ }i | _tt |ƒt | j
ƒƒ}xft|ƒD ]Z}| j
| }|| }|dkrº|jdƒ| jd<