a
]h @ s d dl Z d dlZd dlZd dlZd dlmZ d dlmZ dZdd Z dd Z
G d d
d
Zdd Zd
d Z
G dd dZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZG dd d ZG d!d" d"Zed#krd dlZe Zeej D ]Zee d$eje qe Zeej D ]Z ee d$eje qPe Z!ed%e!j" d& ee! D ]Z#ee# d'e!e# qed( ee$ej%d) Z&e'e&j(D ]*Zee&j)e j*d*d+e&j)e j+ qed, e&,ej%d- D ]Z-ee-d. qe Z.ee.d) e Z/e0d) e/1 e/D ]Z!ee! d$e/e! q\ed/ qFdS )0 N)reduce)bitmasklistz0.7.4c C s t } ttd| S )z) Return True if running on s390 or s390x Zs390)platformmachineboolresearch)r r 1/usr/lib/python3.9/site-packages/procfs/procfs.pyis_s390 s r c C s@ | d rt dd | d S z| d d W S Y dS 0 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 )abr r r
! z!process_cmdline..statcommN)r strip)Zpid_infor r r
process_cmdline s r c @ s e Zd ZdZdZdZdZdZdZdZ dZ
d Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$d Z%d!Z&d!Z'g d"Z(d9d$d%Z)d&d' Z*d(d) Z+d*d+ Z,d,d- Z-d.d/ Z.d0d1 Z/d:d2d3Z0d4d5 Z1d6d7 Z2d8S );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 @l )+pidr stateZppidZpgrpZsessionZtty_nrZtpgidflagsZminfltZcminfltZmajfltZcmajfltutimeZstimeZcutimeZcstimepriorityniceZnum_threadsZitrealvalueZ starttimeZvsizeZrssZrlimZ startcodeZendcodeZ
startstackZkstkespZkstkeipsignalZblockedZ sigignoreZsigcatchZwchanZnswapZcnswapZexit_signal processorrt_priorityZpolicyZdelayacct_blkio_ticksenviron/procc C s. || _ z| | W n ty( Y n0 d S N)r loadFileNotFoundErrorselfr basedirr r r
__init__~ s
zpidstat.__init__c C s
| j | S r+ fieldsr/ Z fieldnamer r r
__getitem__ s zpidstat.__getitem__c C s t | j S r+ listr3 keysr/ r r r
r8 s zpidstat.keysc C s t | j S r+ r7 r3 valuesr9 r r r
r; s zpidstat.valuesc C s
|| j v S r+ r2 r4 r r r
has_key s zpidstat.has_keyc C s | j S r+ r2 r9 r r r
items s z
pidstat.itemsc C s
|| j v S r+ r2 r4 r r r
__contains__ s zpidstat.__contains__c C s zt | d| j d}W n ty. Y n0 | d}| |d d|d }i | _tt |t | j
}t|D ]Z}| j
| }|| }|dkr|d| jd<