HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //lib/fm-agent/dependencies/linux/python3.9/psutil/__pycache__/_pslinux.cpython-39.pyc
a

��i�M�
@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&ddlm'Z'ddlm(Z(ddlm)Z)ddl*m+Z+ddl*m,Z,ddl*m-Z-dd l*m.Z.dd!l*m/Z/dd"l*m0Z0ej1d#k�r�ddl2Z2ndZ2gd$�Z3d%Z4ej5�6d&e�7��Z8e9ed'�Z:e9ed(�Z;e<�Z=e�>d)�Z?e�@�ZAdaBe+�rLd*nd+ZCejDd,kZEd-ZFe2du�rpe
jGZHne2�Id.d/eJe
jG�i�ZKeKjHZHe2du�r�dZLdZMd0ZNd1ZOn Gd2d3�d3e2jI�ZPeQ��RePjS�ejTejUejVejWejXejYejZejZej[ej\ej]ej^d4�Z_ej`ejaejbejcejdejeejfejgejhejiejjd5�Zked6gd7��Zled8gd9��Zmed:gd;��Zned<d=�Zoed>eojpd?�Zqed@gdA��ZredBdCdD�serjp��ZtedEgdF��ZuedGgdH��ZvdIdJ�ZwdKdL�ZxdMdN�Zye"dOdP��Zze=dQfdRdS�Z{zezdT�Wn.e|�y e
�}�edUdV�dWdWdW�a~Yn0dZzddXl�mZWn@e��yvddl�Z�e�j�ddQdY�Z�e9e�dZ��rrd�d[dZ�ZYn0edu�r�e3��d\d]�e�e�D��d^d_�Z�d`da�Z�dbdc�Z�ddde�Z�dfdg�Z�dhdi�Z�djdk�Z�dldm�Z�dndo�Z�ej5�6dp��s�ej5�6dq��rdrds�Z�ndtds�Z�ej�Z�Gdudv�dve|�Z�Gdwdx�dx�Z�e��Z�d�dzd{�Z�d|d}�Z�d~d�Z�ej�Z�d�d�d��Z�Gd�d��d��Z�d�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�Gd�d��d�e<�Z�dS)�zLinux platform implementation.�)�divisionN)�defaultdict)�
namedtuple�)�_common)�_psposix)�
_psutil_linux)�
_psutil_posix)�NIC_DUPLEX_FULL)�NIC_DUPLEX_HALF)�NIC_DUPLEX_UNKNOWN)�AccessDenied)�
NoSuchProcess)�
ZombieProcess)�debug)�decode)�get_procfs_path)�
isfile_strict)�memoize)�memoize_when_activated)�open_binary)�	open_text)�parse_environ_block)�path_exists_strict)�
supports_ipv6)�
usage_percent)�PY3)�FileNotFoundError)�PermissionError)�ProcessLookupError)�b)�
basestring)��)�PROCFS_PATH�IOPRIO_CLASS_NONE�IOPRIO_CLASS_RT�IOPRIO_CLASS_BE�IOPRIO_CLASS_IDLE�CONN_ESTABLISHED�
CONN_SYN_SENT�
CONN_SYN_RECV�CONN_FIN_WAIT1�CONN_FIN_WAIT2�CONN_TIME_WAIT�
CONN_CLOSE�CONN_CLOSE_WAIT�
CONN_LAST_ACK�CONN_LISTEN�CONN_CLOSINGz/sys/class/power_supplyz/proc/%s/smaps�proc_ioprio_get�proc_cpu_affinity_get�
SC_CLK_TCK���i �littlei�
AddressFamily�AF_LINK�r"c@seZdZdZdZdZdZdS)�
IOPriorityrrr;r"N)�__name__�
__module__�__qualname__r%r&r'r(�r@r@�A/usr/lib/fm-agent/dependencies/linux/python3.9/psutil/_pslinux.pyr<xsr<)�R�S�D�T�t�Z�X�x�K�W�I�P)Z01Z02Z03Z04Z05Z06Z07Z08Z09Z0AZ0B�svmem)�total�	available�percent�used�free�active�inactive�buffers�cached�shared�slab�sdiskio)	�
read_count�write_count�
read_bytes�write_bytes�	read_time�
write_timeZread_merged_countZwrite_merged_count�	busy_time�	popenfile)�path�fdZposition�mode�flags�pmemz"rss vms shared text lib data dirty�pfullmem)�uss�pss�swap�
pmmap_grouped)rc�rss�sizerjZshared_cleanZshared_dirtyZ
private_cleanZ
private_dirtyZ
referencedZ	anonymousrk�	pmmap_extzaddr perms � �pio)r[r\r]r^Z
read_charsZwrite_chars�	pcputimes)�user�system�
children_user�children_system�iowaitcCsLt|t�sJ|��t�|�}|�d�d}|�d�rHt|�sH|dd�}|S)zWrapper around os.readlink().�r�
 (deleted)N���)�
isinstancer!�os�readlink�split�endswithr)rcr@r@rAr}�s
r}cCsXtjdtjdtjdi}||tjtjBtjB@}|tj@rH|�ddd�}|�dd�}|S)zZConvert file's open() flags into a readable string.
    Used by Process.open_files().
    �r�wzw+�arzr+)r|�O_RDONLY�O_WRONLY�O_RDWR�O_APPEND�replace)rfZ	modes_maprer@r@rA�file_flags_to_mode�s
r�cCs4|�dd�}d}|rd|}nd|}t�|tj�S)z�Return True if the given name refers to a root device (e.g.
    "sda", "nvme0n1") as opposed to a logical partition (e.g.  "sda1",
    "nvme0n1p1"). If name is a virtual device (e.g. "loop1", "ram")
    return True.
    �/�!Tz
/sys/block/%sz/sys/block/%s/device)r�r|�access�F_OK)�nameZincluding_virtualrcr@r@rA�is_storage_device�s

r�cCs�td|��$}|����dd�}Wd�n1s60Ygd�}t|�}|dkrb|�d�|dkrt|�d�|d	kr�|�d
�td|�adS)z�Set a namedtuple of variable fields depending on the CPU times
    available on this Linux kernel version which may be:
    (user, nice, system, idle, iowait, irq, softirq, [steal, [guest,
     [guest_nice]]])
    Used by cpu_times() function.
    �%s/statrN)rs�nicert�idlerwZirqZsoftirq�Zsteal�	�guest�
�
guest_nice�	scputimes)r�readliner~�len�appendrr�)�procfs_path�f�values�fieldsZvlenr@r@rA�set_scputimes_ntuples	2


r�Tc	CstzF|rt|�nt|��}|����Wd�WS1s:0YWn(ttfyn|turh|YS�Yn0dS)z�Return file content.
    fallback: the value returned in case the file does not exist or
              cannot be read
    binary: whether to open the file in binary or text mode.
    N)rr�read�strip�IOError�OSError�_DEFAULT)�fname�fallback�binaryr�r@r@rA�cats0r��/procr�zuser system idle�)�prlimit)Z	use_errnor�cCs�Gdd�dtj�}|�}|dur8t�||dt�|��}n6|�}|d|_|d|_t�||t�|�t�|��}|dkr�t��}t|t	�
|���|j|jfS)Nc@s eZdZdejfdejfgZdS)zprlimit.<locals>.StructRlimit�rlim_cur�rlim_maxN)r=r>r?�ctypesZ
c_longlongZ_fields_r@r@r@rA�StructRlimitKs�r�rr)r�Z	Structure�libcr�Zbyrefr�r�Z	get_errnor�r|�strerror)�pid�	resource_�limitsr��current�ret�new�errnor@r@rAr�Js

�cCs"g|]}|�d�r|��r|�qS)�RLIM)�
startswith�isupper��.0rIr@r@rA�
<listcomp>c�r�cCs|d}||�dd�}z|d}|d}|d}WntyJ|YS0ztdt��}Wntyt|YS0d}|�@|D]*}|��}|�d�r�|t|��d	�7}q�Wd
�n1s�0Y|t	9}||}	||}
|
t
|
d|�8}
|	|
7}	|	|t
|d|�7}	t|	�S)
a�Fallback for kernels < 3.14 where /proc/meminfo does not provide
    "MemAvailable:" column, see:
    https://blog.famzah.net/2014/09/24/
    This code reimplements the algorithm outlined here:
    https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
        commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773

    XXX: on recent kernels this calculation differs by ~1.5% than
    "MemAvailable:" as it's calculated slightly differently, see:
    https://gitlab.com/procps-ng/procps/issues/42
    https://github.com/famzah/linux-memavailable-procfs/issues/2
    It is still way more realistic than doing (free + cached) though.
    �MemFree:�Cached:rs
Active(file):sInactive(file):�
SReclaimable:z%s/zoneinfoslowrNr;g@)�get�KeyErrorrrr�r�r��intr~�PAGESIZE�min)�memsrSr�Zlru_active_fileZlru_inactive_fileZslab_reclaimabler�Z
watermark_low�line�availZ	pagecacher@r@rA�calculate_avail_vmemks2


4r�cCs�g}i}tdt���:}|D]$}|��}t|d�d||d<qWd�n1sV0Y|d}|d}z|d}Wn ty�d}|�d	�Yn0z|d
}Wn ty�d}|�d�Yn0||�dd�7}z|d
}	WnDt�y,z|d}	Wn"t�y&d}	|�d�Yn0Yn0z|d}
Wn"t�y\d}
|�d�Yn0z|d}WnTt�y�z|d|d|d}Wn"t�y�d}|�d�Yn0Yn0z|d}Wnt�y�d}Yn0||||}
|
dk�r||}
z|d}Wnt�y0t|�}Yn0|dk�rJd}|�d�||k�rX|}t|||dd�}|�r�dd�	|�t
|�dk�r�dndf}t�|t
�t||||
||
||||	|�S)a�Report virtual memory stats.
    This implementation matches "free" and "vmstat -s" cmdline
    utility values and procps-ng-3.3.12 source was used as a reference
    (2016-09-18):
    https://gitlab.com/procps-ng/procps/blob/
        24fd2605c51fccc375ab0287cec33aa767f06718/proc/sysinfo.c
    For reference, procps-ng-3.3.10 is the version available on Ubuntu
    16.04.

    Note about "available" memory: up until psutil 4.3 it was
    calculated as "avail = (free + buffers + cached)". Now
    "MemAvailable:" column (kernel 3.14) from /proc/meminfo is used as
    it's more accurate.
    That matches "available" column in newer versions of "free".
    �
%s/meminfor�rNs	MemTotal:r�sBuffers:rVr�rWr�sShmem:s
MemShared:rXsActive:rTs	Inactive:sInact_dirty:sInact_clean:sInact_laundry:rUsSlab:s
MemAvailable:rP��round_z6%s memory stats couldn't be determined and %s set to 0�, ZwasZwere)rrr~r�r�r�r�r�r�joinr��warnings�warn�RuntimeWarningrN)Zmissing_fieldsr�r�r�r�rOrSrVrWrXrTrUrYrRr�rQ�msgr@r@rA�virtual_memory�s�8���

	


��r�c
Cs�i}tdt���:}|D]$}|��}t|d�d||d<qWd�n1sR0Yz|d}|d}Wn8ty�t��\}}}}}}}||9}||9}Yn0||}t||dd�}	ztd	t��}WnFt�y}
z,d
t	|
�}t
�|t�d}}
WYd}
~
n�d}
~
00|��d}}
|D]n}|�
d��rXt|�d�d�d
d}n&|�
d��r~t|�d�d�d
d}
|du�r,|
du�r,�q��q,d}t
�|t�d}}
Wd�n1�s�0Yt�||||	||
�S)zReturn swap memory metrics.r�rr�rNs
SwapTotal:s	SwapFree:r�z	%s/vmstatzP'sin' and 'sout' swap memory stats couldn't be determined and were set to 0 (%s)spswpin� r#spswpoutzK'sin' and 'sout' swap memory stats couldn't be determined and were set to 0)rrr~r�r��cextZ
linux_sysinforr��strr�r�r�r�r�sswap)r�r�r�r�rOrS�_Zunit_multiplierrRrQ�errr��sin�soutr@r@rA�swap_memorysF8�
(r�cCsrt�}t|�td|��}|����}Wd�n1s<0Y|dttj�d�}dd�|D�}t|�S)z�Return a named tuple representing the following system-wide
    CPU times:
    (user, nice, system, idle, iowait, irq, softirq [steal, [guest,
     [guest_nice]]])
    Last 3 fields may not be available on all Linux kernel versions.
    r�NrcSsg|]}t|�t�qSr@��float�CLOCK_TICKSr�r@r@rAr�_r�zcpu_times.<locals>.<listcomp>)rr�rr�r~r�r��_fields)r�r�r�r�r@r@rA�	cpu_timesSs*r�cCs�t�}t|�g}td|��n}|��|D]L}|�d�r,|��}|dttj�d�}dd�|D�}t|�}|�	|�q,|Wd�S1s�0YdS)zfReturn a list of namedtuple representing the CPU times
    for every CPU available on the system.
    r�scpurcSsg|]}t|�t�qSr@r�r�r@r@rAr�qr�z!per_cpu_times.<locals>.<listcomp>N)
rr�rr�r�r~r�r�r�r�)r��cpusr�r�r�r��entryr@r@rA�
per_cpu_timescs
r�cCs�zt�d�WSty�d}tdt���0}|D]}|���d�r2|d7}q2Wd�n1sb0Y|dkr�t�d�}t	dt���:}|D]$}|�
d	�d}|�|�r�|d7}q�Wd�n1s�0Y|dkr�YdS|YS0dS)
z0Return the number of logical CPUs in the system.�SC_NPROCESSORS_ONLNr�
%s/cpuinfos	processorrNzcpu\dr�rp)r|�sysconf�
ValueErrorrr�lowerr��re�compilerr~�match)�numr�r��searchr@r@rA�cpu_count_logicalws$(

(r�c
Cs2t�}d}d}t�|�p t�|�D]>}t|��"}|�|�����Wd�q"1sV0Yq"t|�}|dkrv|Si}i}tdt���~}|D]h}|����}|s�z|d||d<Wnt	y�Yn0i}q�|�
d�r�|�d	d
�\}	}
t|
�||	<q�Wd�n1�s0Yt
|���}|�p0dS)z-Return the number of CPU cores in the system.z9/sys/devices/system/cpu/cpu[0-9]*/topology/core_cpus_listz?/sys/devices/system/cpu/cpu[0-9]*/topology/thread_siblings_listNrr��	cpu cores�physical id)r�r�s	:r)�set�globr�addr�r�r�rr�r�r�r~r��sumr�)�lsZp1Zp2rcr��result�mappingZcurrent_infor��key�valuer@r@rA�cpu_count_cores�s4
2�
.r�cCs�tdt����}d}d}d}|D]r}|�d�r@t|��d�}n6|�d�r\t|��d�}n|�d�rvt|��d�}|dur |dur |dur q�q Wd�n1s�0Yd}t�||||�S)z*Return various CPU stats as a named tuple.r�Nsctxtrsintrssoftirqr)rrr�r�r~r�	scpustats)r��ctx_switches�
interrupts�soft_interruptsr��syscallsr@r@rA�	cpu_stats�s&


�$�rc	Cshg}tdt���B}|D],}|���d�r|�t|�dd�d��qWd�n1sZ0Y|S)z<Return current CPU frequency from cpuinfo if available.
    r�scpu mhz�:rN)rrr�r�r�r�r~)r�r�r�r@r@rA�_cpu_get_cpuinfo_freq�s:rz'/sys/devices/system/cpu/cpufreq/policy0z$/sys/devices/system/cpu/cpu0/cpufreqc	Cs�t�}t�d�pt�d�}|jdd�d�g}tjj}t|�D]�\}}t|�t|�kr`||}nt||d�dd�}|dur�t||d	�dd�}|dur�t	d
��t
|�d}t
t||d���d}t
t||d
���d}|�t�
|||��q>|S)z�Return frequency metrics for all CPUs.
        Contrarily to other OSes, Linux updates these values in
        real-time.
        z,/sys/devices/system/cpu/cpufreq/policy[0-9]*z)/sys/devices/system/cpu/cpu[0-9]*/cpufreqcSstt�d|����S)Nz[0-9]+)r�r�r��group)rIr@r@rA�<lambda>�r�zcpu_freq.<locals>.<lambda>)r�Zscaling_cur_freqN�r�Zcpuinfo_cur_freqz!can't find current frequency filei�Zscaling_max_freqZscaling_min_freq)rr��sortr|rcr��	enumerater�r��NotImplementedErrorr�r�r�scpufreq)	Z
cpuinfo_freqs�pathsr�Zpjoin�irc�curr�max_�min_r@r@rA�cpu_freq�s,
�
�rcCsdd�t�D�S)z}Alternate implementation using /proc/cpuinfo.
        min and max frequencies are not available and are set to None.
        cSsg|]}t�|dd��qS)r�)rr
r�r@r@rAr�r�zcpu_freq.<locals>.<listcomp>)rr@r@r@rArsc@seZdZdS)�_Ipv6UnsupportedErrorN)r=r>r?r@r@r@rArsrc@sZeZdZdZdd�Zdd�Zdd�Zedd	��Zeddd��Z	edd
d��Z
ddd�Zd
S)�ConnectionsawA wrapper on top of /proc/net/* files, retrieving per-process
    and system-wide open connections (TCP, UDP, UNIX) similarly to
    "netstat -an".

    Note: in case of UNIX sockets we're only able to determine the
    local endpoint/path, not the one it's connected to.
    According to [1] it would be possible but not easily.

    [1] http://serverfault.com/a/417946
    cCs�dtjtjf}dtjtjf}dtjtjf}dtjtjf}dtjdf}|||||f||f|f|f||f|f|f|f||||f||f||fd�|_d|_dS)N�tcp�tcp6�udp�udp6�unix)�allr�tcp4rr�udp4rr�inet�inet4�inet6)�socket�AF_INET�SOCK_STREAM�AF_INET6�
SOCK_DGRAM�AF_UNIX�tmap�_procfs_path)�selfrrrrrr@r@rA�__init__ s$
�
zConnections.__init__cCs�tt�}t�d|j|f�D]�}ztd|j||f�}WnvttfyRYqYqty�}zF|j	t	j
krxWYd}~q|j	t	jkr�t|�WYd}~q�WYd}~qd}~00|�
d�r|dd�dd�}||�|t|�f�q|S)N�%s/%s/fd�%s/%s/fd/%szsocket:[r�r7)r�listr|�listdirr(r}rrr�r��EINVAL�ENAMETOOLONGrr�r�r�)r)r��inodesrd�inoder�r@r@rA�get_proc_inodes7s"
zConnections.get_proc_inodescCsFi}t�D]6}z|�|�|��Wq
tttfy>Yq
Yq
0q
|S�N)�pids�updater3rrr)r)r1r�r@r@rA�get_all_inodesQs
zConnections.get_all_inodesc	Cs�|�d�\}}t|d�}|s dStr.|�d�}|tjkrntrZt�|t�	|�ddd��}q�t�|t�	|��}n~t�	|�}zRtr�t�tj
tjdgt�
d|��R��}n$t�tj
tjdgt�
d|��R��}Wn ty�t�s�t�n�Yn0t�||�S)	a�Accept an "ip:port" address as displayed in /proc/net/*
        and convert it into a human readable form, like:

        "0500000A:0016" -> ("10.0.0.5", 22)
        "0000000000000000FFFF00000100007F:9E49" -> ("::ffff:127.0.0.1", 40521)

        The IP address portion is a little or big endian four-byte
        hexadecimal number; that is, the least significant byte is listed
        first, so we need to reverse the order of the bytes to convert it
        to an IP address.
        The port is represented as a two-byte hexadecimal number.

        Reference:
        http://linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html
        �:�r@�asciiNr7z>4Iz<4I)r~r�r�encoder!r"�
LITTLE_ENDIAN�	inet_ntop�base64�	b16decoder$�struct�pack�unpackr�rrr�addr)rC�family�ip�portr@r@rA�decode_addressas4



��zConnections.decode_addressNccsR|�d�rtj�|�sdSt|td���}|��t|d�D]�\}}z(|��dd�\
}}	}
}}}}}}}Wn$t	y�t
d|||f��Yn0||vr�||d\}
}nd\}
}|dur�||
kr�q<q<|tjkr�t
|}ntj}zt�|	|�}	t�|
|�}
Wnt�yYq<Yn0||||	|
||
fVq<Wd�n1�sD0YdS)	z.Parse /proc/net/tcp* and /proc/net/udp* files.�6N��	bufferingrr�z,error while parsing %s; malformed line %s %rr�Nr7)rr|rc�existsr�BIGFILE_BUFFERINGr�rr~r��RuntimeErrorr!r#�TCP_STATUSESr�	CONN_NONErrGr)�filerD�type_r1�
filter_pidr��linenor�r��laddr�raddr�statusr2r�rdr@r@rA�process_inet�s8���



zConnections.process_inetc
cst|td���}|��|D]�}|��}z|dd�\}}}}}}}	Wn.tyrd|vr^Yqtd||f��Yn0|	|vr�||	}
ndg}
|
D]b\}}|dur�||kr�q�q�t|�dkr�|d	}
nd
}
t�t	|��}d
}tj
}||||
|||fVq�qWd�n1�s0YdS)zParse /proc/net/unix files.rIr�rpz)error while parsing %s; malformed line %rrKNr�r7�)rrMr�r~r�rNr�r�socktype_to_enumr�rP)rQrDr1rSr�r��tokensr�rRr2�pairsr�rdrcrVrWr@r@rA�process_unix�s6��


zConnections.process_unixcCs||jvr,td|d�dd�|jD��f��t�|_|durP|�|�}|sXgSn|��}t�}|j|D]�\}}}d|j|f}|tj	tj
fvr�|j|||||d�}	n|j||||d�}	|	D]L\}
}}}}}
}|r�t
�|
|||||
�}nt
�|
|||||
|�}|�|�q�qht|�S)Nz+invalid %r kind argument; choose between %sr�cSsg|]}t|��qSr@)�reprr�r@r@rAr��r�z(Connections.retrieve.<locals>.<listcomp>z	%s/net/%s)rS)r'r�r�rr(r3r7r�r!r"r$rXr^r�pconn�sconnr�r-)r)�kindr�r1r�Z
proto_namerDrRrcr�rdrUrVrWZ	bound_pid�connr@r@rA�retrieve�s<
�

����zConnections.retrieve)N)N)N)r=r>r?�__doc__r*r3r7�staticmethodrGrXr^rdr@r@r@rArs
2'%rrcCs
t�|�S)z$Return system-wide open connections.)�_connectionsrd)rbr@r@rA�net_connectionssrhcCs�tdt���}|��}Wd�n1s,0Yi}|dd�D]�}|�d�}|dkshJt|���|d|���}||dd�����}tt|�\}}}	}
}}}
}}}}}}}}}|||||	||
|f||<qF|S)zsReturn network I/O statistics for every network interface
    installed on the system as a dict of raw tuples.
    z
%s/net/devNr;r8rr)	rr�	readlines�rfindr_r�r~�mapr�)r��lines�retdictr�Zcolonr�r��
bytes_recv�packets_recv�errin�dropinZfifoinZframeinZcompressedinZmulticastin�
bytes_sent�packets_sent�errout�dropoutZfifooutZ
collisionsoutZ
carrieroutZ
compressedoutr@r@rA�net_io_counters
s:&
��
rvc	Cs�tjttjttjti}t���}i}|D]�}z&t	�
|�}t	�|�}t�|�\}}Wn<t
y�}z$|jtjkrr�nt|�WYd}~q(d}~00t�|||||�||<q(|S)z)Get NIC stats (isup, duplex, speed, mtu).N)r�ZDUPLEX_FULLr
ZDUPLEX_HALFrZDUPLEX_UNKNOWNrrv�keys�
cext_posixZ
net_if_mtuZnet_if_is_runningZnet_if_duplex_speedr�r�ZENODEVrr�	snicstats)	Z
duplex_map�namesr�r��mtu�isup�duplex�speedr�r@r@rA�net_if_stats/s"�


rFcCs�dd�}dd�}tj�dt��r*|�}n"tj�d�r>|�}ntdt���i}|D]T}|\
}}}}	}
}}}
}}|s~t|�s~qT|	t9}	|
t9}
|||	|
|||
||f	||<qT|S)zcReturn disk I/O statistics for every disk installed on the
    system as a dict of raw tuples.
    cssDtdt���}|��}Wd�n1s,0Y|D�]}|��}t|�}|dkr�|d}t|d�}tt|dd��\
}}}	}
}}}
}}}n�|dks�|dkr�|d}tt|dd��\}}}}	}
}}}
}}}nN|dk�r|d}tt|dd��\}}}
}d	}	}
}}}ntd
|��|||
|||	|
|||f
Vq:dS)N�%s/diskstats�r"r;r#��rYrz!not sure how to interpret line %r)rrrir~r�r�rkr�)r�rlr�r�Zflenr��reads�reads_merged�rbytes�rtime�writes�
writes_merged�wbytes�wtimer�rar@r@rA�read_procfsRs4&
�
��
�
�z%disk_io_counters.<locals>.read_procfscss�t�d�D]�}t�tj�d|��D]�\}}}d|vr6q"ttj�|d��� }|������}Wd�n1sn0Ytj�	|�}t
t|dd��\
}}}	}
}}}
}}}||||	|
|
||||f
Vq"q
dS)N�
/sys/block�statr�)r|r.�walkrcr�rr�r�r~�basenamerkr�)�block�rootr��filesr�r�r�r�r�r�r�r�r�r�r�rar@r@rA�
read_sysfs}s.��z$disk_io_counters.<locals>.read_sysfsr�r�zC%s/diskstats nor /sys/block filesystem are available on this system)r|rcrLrrr��DISK_SECTOR_SIZE)�perdiskr�r��genrmr�r�r�r�r�r�r�r�r�r�rar@r@rA�disk_io_countersNs0+
����
r�c@s@eZdZdZddgZdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�RootFsDeviceFinderaEdisk_partitions() may return partitions with device == "/dev/root"
    or "rootfs". This container class uses different strategies to try to
    obtain the real device path. Resources:
    https://bootlin.com/blog/find-root-device/
    https://www.systutorials.com/how-to-find-the-disk-where-root-is-on-in-bash-on-linux/
    �major�minorcCs(t�d�j}t�|�|_t�|�|_dS)Nr�)r|r��st_devr�r�)r)�devr@r@rAr*�szRootFsDeviceFinder.__init__cCs�tdt����}|��dd�D]�}|��}t|�dkr:q |d��rRt|d�nd}|d��rnt|d�nd}|d}||jkr ||jkr |r d|Wd�Sq Wd�n1s�0YdS)Nz
%s/partitionsr;r#rrr"�/dev/%s)	rrrir~r��isdigitr�r�r�)r)r�r�r�r�r�r�r@r@rA�ask_proc_partitions�sz&RootFsDeviceFinder.ask_proc_partitionscCs�d|j|jf}t|��T}|D]>}|�d�r|���d�d}|rd|Wd�SqWd�n1sr0YdS)Nz/sys/dev/block/%s:%s/ueventzDEVNAME=r;r�)r�r�rr�r��
rpartition)r)rcr�r�r�r@r@rA�ask_sys_dev_block�s

z$RootFsDeviceFinder.ask_sys_dev_blockc	Cs�d|j|jf}t�d�}|D]�}zt|�}WntyDYqYq0|�R|����}||kr�tj	�
tj	�|��}d|Wd�SWd�q1s�0YqdS)Nz%s:%sz/sys/class/block/*/devr�)r�r�r�Ziglobrrr�r�r|rcr��dirname)r)Zneedler�rQr��datar�r@r@rA�ask_sys_class_block�s

z&RootFsDeviceFinder.ask_sys_class_blockc
Cs�d}|durJz|��}Wn0ttfyH}zt|�WYd}~n
d}~00|dur�z|��}Wn0ttfy�}zt|�WYd}~n
d}~00|dur�z|��}Wn0ttfy�}zt|�WYd}~n
d}~00|dur�tj�|�r�|SdSr4)	r�r�r�rr�r�r|rcrL)r)rcr�r@r@rA�find�s$zRootFsDeviceFinder.findN)
r=r>r?re�	__slots__r*r�r�r�r�r@r@r@rAr��s
	r�c	Cs@t�}t�}td|��\}|D]F}|��}|�d�sD|�|���q|�d�d}|dkr|�d�qWd�n1sz0Y|dkr�tj�	d�r�tj�
d�}ntj�
d	|�}g}t�|�}|D]r}	|	\}
}}}|
d
kr�d}
|
dvr�t
���p�|
}
|�s|
dks�||v�rq�d}
}t�|
||||
|�}|�|�q�|S)
z8Return mounted disk partitions as a list of namedtuples.z%s/filesystemsZnodev�	rZzfsNr�z	/etc/mtabz%s/self/mountsZnonerZ)z	/dev/rootZrootfs)r�rrr�r�r�r~r|rc�isfile�realpathr��disk_partitionsr�r�r�	sdiskpartr�)rZfstypesr�r�r��fstypeZmounts_path�retlistZ
partitions�	partition�device�
mountpoint�opts�maxfile�maxpath�ntupler@r@rAr��s<
*
�r�cCs\t�t�}t�d�}|�t�d��ttdd�|D���}t�d�}t�d�}|D]"}|�	d|�}||vrR|�
|�qR|D�]}z>|d}tt|��d	}t
j�t
j�|�d
�}t|dd�}	Wntttfy�YqzYn0t|d
dd�}
t|ddd�}t|dddd�}|
du�rBzt|
�d	}
Wnt�y@d}
Yn0|du�rvzt|�d	}Wnt�ytd}Yn0||	�
|||
|f�qz|�sTt�d�}tt|��}|D�]�}z<t
j�|d�}tt|��d	}t
j�|d�}t|dd�}	WnBtttf�y2}
z"t|
�WYd}
~
�q�WYd}
~
n
d}
~
00t�|d�}tdd�|D��}d}d}
|D]�}t
j�||d�}t|ddd�}|dk�r�tt
j�||d�dd�}n$|dk�r�tt
j�||d�dd�}
|
du�rzt|
�d	}
Wnt�yd}
Yn0|du�r`zt|�d	}Wnt�y4d}Yn0�q`||	�
d||
|f��q�t|�S)a�Return hardware (CPU and others) temperatures as a dict
    including hardware name, label, current, max and critical
    temperatures.

    Implementation notes:
    - /sys/class/hwmon looks like the most recent interface to
      retrieve this info, and this implementation relies on it
      only (old distros will probably use something else)
    - lm-sensors on Ubuntu 16.04 relies on /sys/class/hwmon
    - /sys/class/thermal/thermal_zone* is another one but it's more
      difficult to parse
    z/sys/class/hwmon/hwmon*/temp*_*z&/sys/class/hwmon/hwmon*/device/temp*_*cSsg|]}|�d�d�qS�r�r�r~r�r@r@rAr�7r�z(sensors_temperatures.<locals>.<listcomp>z5/sys/devices/platform/coretemp.*/hwmon/hwmon*/temp*_*z'/sys/devices/platform/coretemp.*/hwmon/z/sys/class/hwmon/�_inputg@�@r�F�r�Z_maxNr	Z_crit�_labelrZ�r�r�z /sys/class/thermal/thermal_zone*Ztemp�typez/trip_point*cSs,g|]$}d�tj�|��d�dd���qS)r�rr")r�r|rcr�r~)r��pr@r@rAr�ws��Z_type�criticalZ_temp�high)�collectionsrr-r��extend�sortedr�r�r��subr�r�r�r|rcr�r�r�r�r�r�dict)r��	basenamesZ
basenames2�replr�Zaltname�basercr��	unit_namer�r��labelr�Z
trip_pathsZtrip_pointsZ
trip_pointZ	trip_typer@r@rA�sensors_temperatures$s�

�

	






$�
�
�


r�cCs�t�t�}t�d�}|s"t�d�}ttdd�|D���}|D]�}ztt|d��}Wn<tt	fy�}z t
|�WYd}~q<WYd}~n
d}~00ttj�
tj�|�d�dd	�}t|d
ddd�}||�t�||��q<t|�S)
a�Return hardware fans info (for CPU and other peripherals) as a
    dict including hardware label and current speed.

    Implementation notes:
    - /sys/class/hwmon looks like the most recent interface to
      retrieve this info, and this implementation relies on it
      only (old distros will probably use something else)
    - lm-sensors on Ubuntu 16.04 relies on /sys/class/hwmon
    z/sys/class/hwmon/hwmon*/fan*_*z%/sys/class/hwmon/hwmon*/device/fan*_*cSsg|]}|�d�d�qSr�r�r�r@r@rAr��r�z sensors_fans.<locals>.<listcomp>r�Nr�Fr�r�rZr�)r�rr-r�r�r�r�r�r�r�rr|rcr�r�r�r�sfanr�)r�r�r�r�r�r�r�r@r@rA�sensors_fans�s"



"�r�cs�t���fdd�}dd�t�t�D�}|s.dStj�tt|�d�}||d|d�}||d	|d
�}||d|d�}||d
�}|dur�|dur�zd||}Wq�ty�d}Yq�0n tt	|ddd��}|dkr�dSd}|tj�td�tj�td��}	|	du�r|	dk}n4t	|dddd��
�}
|
dk�r<d}n|
dv�rJd}|�rXtj}nt|du�r�|du�r�zt||d�}Wnt�y�tj
}Yn0n.|du�r�t|d�}|dk�r�tj
}ntj
}t�|||�S)aReturn battery information.
    Implementation note: it appears /sys/class/power_supply/BAT0/
    directory structure may vary and provide files with the same
    meaning but under different names, see:
    https://github.com/giampaolo/psutil/issues/966
    c	sL|D]B}t|�d�}|�krzt|�WStyD|YS0qdS)zvAttempt to read the content of multiple files which may
        not exist. If none of them exist return None.
        r	N)r�r�r�)rrcr���nullr@rA�	multi_cat�sz"sensors_battery.<locals>.multi_catcSs&g|]}|�d�sd|��vr|�qS)ZBATZbattery)r�r�r�r@r@rAr��s�z#sensors_battery.<locals>.<listcomp>Nrz/energy_nowz/charge_nowz
/power_nowz/current_nowz/energy_fullz/charge_fullz/time_to_empty_nowgY@r�z	/capacityr7r	z
AC0/onlinez	AC/onlinerz/statusrZFr�Zdischarging)ZchargingZfullTi�<)�objectr|r.�POWER_SUPPLY_PATHrcr�r��ZeroDivisionErrorr�r�r�r�POWER_TIME_UNLIMITED�POWER_TIME_UNKNOWN�sbattery)r�Zbatsr�Z
energy_nowZ	power_nowZenergy_fullZ
time_to_emptyrQ�
power_pluggedZonlinerW�secsleftr@r�rA�sensors_battery�sh
����





r�c
Cs\g}t��}|D]F}|\}}}}}}|s*q|dvr6d}t�||pBd|||�}	|�|	�q|S)z:Return currently connected users as a list of namedtuples.)z:0.0z:0�	localhostN)r��usersr�suserr�)
r��rawlist�itemrsZtty�hostnameZtstampZuser_processr��ntr@r@rAr�sr�cCs�dt�}t|��^}|D]<}|�d�rt|����d�}|a|Wd�Sqtd|��Wd�n1sv0YdS)zAReturn the system boot time expressed in seconds since the epoch.r�sbtimerNzline 'btime' not found in %s)rrr�r�r�r~�	BOOT_TIMErN)rcr�r�r�r@r@rA�	boot_time(s


�r�cCsdd�t�tt���D�S)z7Returns a list of PIDs currently running on the system.cSsg|]}|��rt|��qSr@)r�r�r�r@r@rAr�=r�zpids.<locals>.<listcomp>)r|r.r rr@r@r@rAr5;sr5c	Cs�t�|�sdSz�dt�|f}t|��\}|D]:}|�d�r,t|��d�}||kWd�WSq,td|��Wd�n1s�0YWn ttfy�|t	�vYS0dS)zcCheck for the existence of a unix PID. Linux TIDs are not
    supported (always return False).
    F�%s/%s/statussTgid:rNz'Tgid' line not found in %s)
r�
pid_existsrrr�r�r~r��EnvironmentErrorr5)r�rcr�r�Ztgidr@r@rAr�@s



.r�c
Cs�i}t�}t�D]�}z<td||f��}|��}Wd�n1sD0YWnttfyfYq0|�d�}||dd���}t|d�}|||<q|S)zsObtain a {pid: ppid, ...} dict for all running processes in
    one shot. Used to speed up Process.children().
    �
%s/%s/statN�)r;r)	rr5rr�rrrjr~r�)r�r�r�r�r��rparZdset�ppidr@r@rA�ppid_map`s
*

r�cst����fdd��}|S)zlDecorator which translates bare OSError and IOError exceptions
    into NoSuchProcess and AccessDenied.
    cs�z�|g|�Ri|��WSty8t|j|j��YnXtyVt|j|j��Yn:ty�tj�	d|j
|jf�s�t|j|j���Yn0dS)N�%s/%s)rr
r��_namerrrr|rcrLr()r)�args�kwargs��funr@rA�wrapperzsz wrap_exceptions.<locals>.wrapper)�	functools�wraps)r�r�r@r�rA�wrap_exceptionsvs
r�c@sneZdZdZgd�Zdd�Zdd�Zeedd���Z	eed	d
���Z
eedd���Zd
d�Zdd�Z
edd��Zdd�Zedd��Zedd��Zedd��Zej�de���r�edd��Zedd��Zed d!��Zed\d#d$��Zed%d&��Zed'd(��Ze�r(ee�d)�e�d*�e�d+�fd,d-��Z neZ e�r>ed.d/��Z!ed0d1��Z"ee�d2�fd3d4��Z#ee�d5�fd6d7��Z$ed8d9��Z%ed:d;��Z&ed<d=��Z'e(�r�ed>d?��Z)e�d@�fdAdB�Z*edCdD��Z+e,�r�edEdF��Z-edGdH��Z.e/d"u�red]dIdJ��Z0edKdL��Z1edMdN��Z2ed^dPdQ��Z3edRdS��Z4edTdU��Z5ee�dV�fdWdX��Z6ee�dY�fdZd[��Z7d"S)_�ProcesszLinux process implementation.)r�r��_ppidr(�_cachecCs||_d|_d|_t�|_dSr4)r�r�r�rr()r)r�r@r@rAr*�szProcess.__init__cCst�d|j|jf�dS)z+Raise NSP if the process disappeared on us.r�N)r|r�r(r��r)r@r@rA�
_assert_alive�szProcess._assert_alivecCs�td|j|jf��}|��}Wd�n1s20Y|�d�}||�d�d|�}||dd���}i}||d<|d|d	<|d|d
<|d|d<|d
|d<|d|d<|d|d<|d|d<|d|d<|d|d<|d|d<|S)aZParse /proc/{pid}/stat file and return a dict with various
        process info.
        Using "man proc" as a reference: where "man proc" refers to
        position N always substract 3 (e.g ppid position 4 in
        'man proc' == position 1 in here).
        The return value is cached in case oneshot() ctx manager is
        in use.
        r�Nr��(rr;r�rrWr�r#�ttynr��utime��stime�
�children_utimer��children_stime��create_time�$�cpu_num�'�blkio_ticks)rr(r�r�rjr�r~)r)r�r�r�r�r�r�r@r@rA�_parse_stat_file�s$&
zProcess._parse_stat_filecCs@td|j|jf��}|��Wd�S1s20YdS)z�Read /proc/{pid}/stat file and return its content.
        The return value is cached in case oneshot() ctx manager is
        in use.
        r�N)rr(r�r��r)r�r@r@rA�_read_status_file�szProcess._read_status_filecCsHtd|j|jftd��}|����Wd�S1s:0YdS)Nz%s/%s/smapsrI)rr(r�rMr�r�r
r@r@rA�_read_smaps_file�s
�zProcess._read_smaps_filecCs(|j�|�|j�|�|j�|�dSr4)r	�cache_activaterrr�r@r@rA�
oneshot_enter�szProcess.oneshot_entercCs(|j�|�|j�|�|j�|�dSr4)r	�cache_deactivaterrr�r@r@rA�oneshot_exit�szProcess.oneshot_exitcCs|��d}trt|�}|S)Nr�)r	rr)r)r�r@r@rAr��szProcess.namec	Cs�ztd|j|jf�WSttfyvtj�d|j|jf�rFYdSt|j�s`t	|j|j
��nt|j|j
|j��Yn t
y�t|j|j
��Yn0dS)Nz	%s/%s/exer�rZ)r}r(r�rrr|rc�lexistsr�rr�rr�rr
r�r@r@rA�exe�s
zProcess.execCs�td|j|jf��}|��}Wd�n1s20Y|sDgS|�d�rRdnd}|�|�rl|dd�}|�|�}|dkr�t|�dkr�d|vr�|�d�}|S)Nz
%s/%s/cmdlinerxrpr7r)rr(r�r�rr~r�)r)r�r��sep�cmdliner@r@rAr�s&


zProcess.cmdlinecCsDtd|j|jf��}|��}Wd�n1s20Yt|�S)Nz
%s/%s/environ)rr(r�r�r)r)r�r�r@r@rA�environs&zProcess.environcCs<t|��d�}t��}z
||WSty6YdS0dS)Nr�)r�r	rZget_terminal_mapr�)r)Ztty_nrr'r@r@rA�terminals
zProcess.terminalz/proc/%s/ioc
Csd|j|jf}i}t|��\}|D]F}|��}|r"z|�d�\}}WntyZYq"Yq"0t|�||<q"Wd�n1s~0Y|s�td|��z,t|d|d|d|d|d|d	�WSt	�y}z"td
|d||f��WYd}~n
d}~00dS)Nz%s/%s/ios: z%s file was emptyssyscrssyscws
read_bytesswrite_bytessrcharswcharz1%r field was not found in %s; found fields are %rr)
r(r�rr�r~r�r�rNrqr�)r)r�r�r�r�r�r�r�r@r@rA�io_counterss4

,��zProcess.io_counterscCsh|��}t|d�t}t|d�t}t|d�t}t|d�t}t|d�t}t|||||�S)Nr�r�rrr)r	r�r�rr)r)r�r�r�rrrwr@r@rAr�<szProcess.cpu_timescCst|��d�S)zWhat CPU the process is on.r�r�r	r�r@r@rArFszProcess.cpu_numNcCst�|j||j�Sr4)rZwait_pidr�r�)r)�timeoutr@r@rA�waitKszProcess.waitcCs&t|��d�}tpt�}|t|S)Nr)r�r	r�r�r�)r)�ctimeZbtr@r@rArOs
zProcess.create_timec	Csttd|j|jf��<}dd�|����dd�D�\}}}}}}}Wd�n1sV0Yt|||||||�S)Nz%s/%s/statmcSsg|]}t|�t�qSr@)r�r�r�r@r@rAr�ir�z'Process.memory_info.<locals>.<listcomp>rY)rr(r�r�r~rg)	r)r��vmsrmrX�text�libr�Zdirtyr@r@rA�memory_infoZs
�.zProcess.memory_infos\nPrivate.*:\s+(\d+)s\nPss\:\s+(\d+)s\nSwap\:\s+(\d+)c	Csj|��}|��}ttt|�|���d}ttt|�|���d}ttt|�|���d}t||||f�S)Nr�)rrr�rkr��findallrh)	r)Z_private_reZ_pss_reZ_swap_reZ	basic_memZ
smaps_datarirjrkr@r@rA�memory_full_infops
zProcess.memory_full_infocCsRdd�}|��}|sgS|�d�}g}|�d�}|g}|||�D�]
\}}|�dd�}z|\}	}
}}}
}Wn(ty�|dg\}	}
}}}
}Yn0|s�d}n2tr�t|�}|��}|�d	�r�t|�s�|dd
�}|�	t|	�t|
�||�
dd�|�
dd�|�
d
d�|�
dd�|�
dd�|�
dd�|�
dd�|�
dd�|�
dd�|�
dd�f
�q@|S)aPReturn process's mapped memory regions as a list of named
            tuples. Fields are explained in 'man proc'; here is an updated
            (Apr 2012) version: http://goo.gl/fmebo

            /proc/{PID}/smaps does not exist on kernels < 2.6.14 or if
            CONFIG_MMU kernel configuration option is not enabled.
            c	ss�i}|D]�}|�dd�}|d�d�s@|��|fV|�|�qzt|d�d||d<Wqty�|d�d�r~Yqntd|��Yq0q|��|fVdS)N�rrrr�sVmFlags:z#don't know how to interpret line %r)r~r�popr�r�r�r�)rl�
current_blockr�r�r�r@r@rA�
get_blocks�s�z'Process.memory_maps.<locals>.get_blocks�
rNr"rZz[anon]ryrzsRss:sSize:sPss:s
Shared_Clean:s
Shared_Dirty:sPrivate_Clean:sPrivate_Dirty:sReferenced:s
Anonymous:sSwap:)rr~r#r�rrr�rrr�r�)r)r%r�rlr��
first_liner$�headerZhfieldsrC�perms�offsetr�r2rcr@r@rA�memory_maps�sL	

�
�









�
zProcess.memory_mapsc	Cs^ztd|j|jf�WSttfyXt|j�sBt|j|j��nt|j|j|j	��Yn0dS)Nz	%s/%s/cwd)
r}r(r�rrr�rr�rr�r�r@r@rA�cwd�s
zProcess.cwdsctxt_switches:\t(\d+)cCsL|��}|�|�}|s,td|j|jf��nt�t|d�t|d��SdS)Nz�'voluntary_ctxt_switches' and 'nonvoluntary_ctxt_switches'lines were not found in %s/%s/status; the kernel is probably older than 2.6.23rr)rr rr(r�r�pctxswr�)r)Z	_ctxsw_rer�Zctxswr@r@rA�num_ctx_switches�s
���zProcess.num_ctx_switchessThreads:\t(\d+)cCs|��}t|�|�d�S�Nr)rr�r )r)Z_num_threads_rer�r@r@rA�num_threads�szProcess.num_threadsc	Cst�d|j|jf�}|��g}d}|D]�}d|j|j|f}z8t|��}|����}Wd�n1sl0YWnty�d}Yq*Yn0||�	d�dd�}|�
d�}t|d�t}	t|d	�t}
t
�t|�|	|
�}|�|�q*|r�|��|S)
Nz
%s/%s/taskFz%s/%s/task/%s/statTr�r;r�r�r�)r|r.r(r�r
rr�r�rr�r~r�r�r�pthreadr�r�r�)r)Z
thread_idsr��
hit_enoentZ	thread_idr�r��str�r�r�r�r@r@rA�threads�s.
�
.

zProcess.threadscCst�|j�Sr4)rx�getpriorityr�r�r@r@rA�nice_getszProcess.nice_getcCst�|j|�Sr4)rx�setpriorityr�)r)r�r@r@rA�nice_setszProcess.nice_setcCst�|j�Sr4)r�r5r�r�r@r@rA�cpu_affinity_get"szProcess.cpu_affinity_getsCpus_allowed_list:\t(\d+)-(\d+)cCsV|��}|�|�}|r@ttt|dd�t|dd�d��Stttt����SdS)Nrr)rr r-�ranger�r�r�)r)�_rer�r�r@r@rA�_get_eligible_cpus&s

*zProcess._get_eligible_cpusc
Cs�zt�|j|�Wn�ttfy�}zxt|t�s<|jtjkr�|��}t	t
tt����}|D]4}||vrvtd||f��||vrZtd||f��qZ�WYd}~n
d}~00dS)Nz(invalid CPU number %r; choose between %sz0CPU number %r is not eligible; choose between %s)
r�Zproc_cpu_affinity_setr�r�r�r{r�r/r<�tupler:r�r�)r)r�r�Z
eligible_cpusZall_cpus�cpur@r@rA�cpu_affinity_set0s(����zProcess.cpu_affinity_setcCs,t�|j�\}}tdur t|�}t�||�Sr4)r�r4r��enumr<r�pionice�r)�ioclassr�r@r@rA�
ionice_getFszProcess.ionice_getcCsP|durd}|r(|ttfvr(td|��|dks8|dkr@td��t�|j||�S)Nrz%r ioclass accepts no valuerYzvalue not in 0-7 range)r(r%r�r�Zproc_ioprio_setr�rBr@r@rA�
ionice_setMszProcess.ionice_setc
Cs�|jdkrtd��zD|dur*t|j|�WSt|�dkrFtdt|���t|j||�WnPty�}z8|jtjkr�t|j�r�t	|j|j
|j��n�WYd}~n
d}~00dS)Nrz)can't use prlimit() against PID 0 processr;z4second argument must be a (soft, hard) tuple, got %s)r�r�r�r�r_r�r�ZENOSYSr�rr�r�)r)r�r�r�r@r@rA�rlimitYs 
��zProcess.rlimitcCs$|��d}tr|��}t�|d�S)NrW�?)r	rr�
PROC_STATUSESr�)r)Zletterr@r@rArWsszProcess.statusc
Cs�g}t�d|j|jf�}d}|D�]^}d|j|j|f}zt|�}Wnzttfydd}Yq"Yq"ty�}zF|jtj	kr�WYd}~q"|jtj
kr�t|�WYd}~q"�WYd}~q"d}~00|�d�r"t
|�r"d|j|j|f}zXt|��:}t|����d�}	t|����dd�}
Wd�n1�s20YWnt�yVd}Yq"0t|
�}t|t|�t|	�||
�}|�|�q"|�r�|��|S)	Nr+Fr,Tr�z%s/%s/fdinfo/%srr�)r|r.r(r�r}rrr�r�r/r0rr�rrr�r�r~r�rbr�r�)
r)r�r�r2rdrQrcr�r��posrfrer�r@r@rA�
open_files{sF

�
:
�zProcess.open_filesrcCst�||j�}|��|Sr4)rgrdr�r�)r)rbr�r@r@rA�connections�szProcess.connectionscCstt�d|j|jf��S)Nr+)r�r|r.r(r�r�r@r@rA�num_fds�szProcess.num_fdscCst|��d�S)Nr�rr�r@r@rAr��szProcess.ppidsUid:\t(\d+)\t(\d+)\t(\d+)cCs6|��}|�|�d\}}}t�t|�t|�t|��Sr/)rr r�puidsr�)r)Z_uids_rer��real�	effective�savedr@r@rA�uids�szProcess.uidssGid:\t(\d+)\t(\d+)\t(\d+)cCs6|��}|�|�d\}}}t�t|�t|�t|��Sr/)rr r�pgidsr�)r)Z_gids_rer�rNrOrPr@r@rA�gids�szProcess.gids)N)N)r)8r=r>r?rer�r*r�r�rr	rrrrr�rrrrr|rcrL�getpidrr�rrrr�	HAS_SMAPSr�r�r!r+r,r.r0r4r6r8�HAS_CPU_AFFINITYr9r<r?�HAS_PROC_IO_PRIORITYrDrEr�rFrWrJrKrLr�rQrSr@r@r@rAr��s�!



	

	



�
C

�




�




	


/

r�)N)r)F)F)�re�
__future__rr>r�r�r�r�r|r�r!r@�sys�	tracebackr�rrrZrrrr�r	rxr
rrr
rrrrrrrrrrrrrr�_compatrrrrr r!�version_infor@�__extra__all__r�rcrLrTrU�hasattrrWrVr�r�r�r�Zgetpagesizer�r�rM�	byteorderr<r��	AF_PACKETr:�IntEnumr�r9r%r&r'r(r<�globalsr6�__members__�STATUS_RUNNING�STATUS_SLEEPING�STATUS_DISK_SLEEP�STATUS_STOPPED�STATUS_TRACING_STOP�
STATUS_ZOMBIE�STATUS_DEAD�STATUS_WAKE_KILL�
STATUS_WAKING�STATUS_IDLE�
STATUS_PARKEDrHr)r*r+r,r-r.r/r0r1r2r3rOrNrZrbrgr�rhrlr�rorqrrr}r�r�r�r��	Exception�	print_excr�r��resource�ImportErrorr�ZCDLLr�r��dirr�r�r�r�r�r�r�rrr�net_if_addrsrrrgrhrvr�
disk_usager�r�r�r�r�r�r�r�r5r�r�r�r�r@r@r@rA�<module>sb






�
�����
���




�	4z:*
�
!o
%
_J
-q a