HEX
Server: LiteSpeed
System: Linux ws4.angoweb.net 5.14.0-611.13.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 11 04:57:59 EST 2025 x86_64
User: tswangoe (2287)
PHP: 8.1.33
Disabled: show_source, system, shell_exec, passthru, exec, phpinfo, popen, proc_open
Upload Files
File: //proc/self/root/usr/local/lib64/python3.9/site-packages/psutil/__pycache__/_pslinux.cpython-39.pyc
a

q�dgZ�
@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&ddlm'Z'ddlm(Z(ddlm)Z)ddlm*Z*ddl+m,Z,dd l+m-Z-dd!l+m.Z.dd"l+m/Z/dd#l+m0Z0dd$l+m1Z1e,�r�ddl2Z2ndZ2gd%�Z3d&Z4ej5�6d'e�7��Z8ej5�6d(e�7��Z9e:ed)�Z;e:ed*�Z<e�=d+�Z>e�?�Z@daAejBd,kZCd-ZDe2du�rze
jEZFne2�Gd.d/eHe
jE�i�ZIeIjFZFe2du�r�dZJdZKd0ZLd1ZMn Gd2d3�d3e2jG�ZNeO��PeNjQ�ejRejSejTejUejVejWejXejXejYejZej[ej\d4�Z]ej^ej_ej`ejaejbejcejdejeejfejgejhd5�Zied6gd7��Zjed8gd9��Zked:gd;��Zled<d=�Zmed>emjnd?�Zoed@gdA��ZpedBdCdD�qepjn��ZredEgdF��ZsedGgdH��ZtdIdJ�ZudKdL�ZvdMdN�Zwe#dOdP��ZxzexdQ�WnDey�y2Zzz*edRez�edSdT�dUdUdU�a{WYdZz[zn
dZz[z00dZ|zddVl}m|Z|Wn@e~�y�ddlZej�ddWdX�Z�e:e�dY��r�d�dZdY�Z|Yn0e|du�r�e3��d[d\�e�e�D��d]d^�Z�d_d`�Z�dadb�Z�dcdd�Z�dedf�Z�dgdh�Z�didj�Z�dkdl�Z�dmdn�Z�ej5�6do��sej5�6dp��rdqdr�Z�ndsdr�Z�ej�Z�Gdtdu�duey�Z�Gdvdw�dw�Z�e��Z�d�dydz�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��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)�bcat)�cat)�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)ZPROCFS_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/smapsz/proc/%s/smaps_rollup�proc_ioprio_get�proc_cpu_affinity_get�
SC_CLK_TCK�littlei�
AddressFamily�AF_LINK��c@seZdZdZdZdZdZdS)�
IOPriorityrrr9r:N)�__name__�
__module__�__qualname__r$r%r&r'�r?r?�;/usr/local/lib64/python3.9/site-packages/psutil/_pslinux.pyr;ysr;)�R�S�D�T�t�Z�X�x�K�W�I�P)Z01�02Z03Z04Z05Z06Z07Z08Z09Z0AZ0B�svmem)�total�	available�percent�used�free�active�inactive�buffers�cached�shared�slab�sdiskio)	�
read_count�write_count�
read_bytes�write_bytesZ	read_timeZ
write_timeZread_merged_countZwrite_merged_count�	busy_time�	popenfile)�path�fd�position�mode�flags�pmemz"rss vms shared text lib data dirty�pfullmem)�uss�pss�swap�
pmmap_grouped)ra�rss�sizeriZshared_cleanZshared_dirtyZ
private_cleanZ
private_dirtyZ
referencedZ	anonymousrj�	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)rar?r?r@r|�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)reZ	modes_maprdr?r?r@�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_virtualrar?r?r@�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)rr�nicers�idlervZirqZsoftirq�Zsteal�	Zguest�
Z
guest_nice�	scputimes)r�readliner}�len�appendrr�)�procfs_path�f�values�fieldsZvlenr?r?r@�set_scputimes_ntuples	2


r��/procz ignoring exception on import: %rr�zuser system idle�)�prlimitT)�	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>�ctypes�
c_longlong�_fields_r?r?r?r@�StructRlimit>s�r�rr)r��	Structure�libcr��byrefr�r��	get_errno�OSErrorr{�strerror)�pid�	resource_�limitsr��current�ret�newZerrno_r?r?r@r�=s

�cCs"g|]}|�d�r|��r|�qS)ZRLIM)�
startswith�isupper��.0rHr?r?r@�
<listcomp>Y�r�c
CsB|d}||�dd�}z|d}|d}|d}Wn:tyn}z"td|jd�|WYd}~Sd}~00ztd	t��}Wnty�|YS0d}|�@|D]*}	|	��}	|	�d
�r�|t	|	�
�d�7}q�Wd�n1s�0Y|t9}||}
||}|t|d|�8}|
|7}
|
|t|d
|�7}
t	|
�S)ayFallback for kernels < 3.14 where /proc/meminfo does not provide
    "MemAvailable", 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

    We use this function also when "MemAvailable" returns 0 (possibly a
    kernel bug, see: https://github.com/giampaolo/psutil/issues/1915).
    In that case this routine matches "free" CLI tool result ("available"
    column).

    XXX: on recent kernels this calculation may differ by ~1.5% compared
    to "MemAvailable:", as it's calculated slightly differently.
    It is still way more realistic than doing (free + cached) though.
    See:
    * https://gitlab.com/procps-ng/procps/issues/42
    * https://github.com/famzah/linux-memavailable-procfs/issues/2
    �MemFree:�Cached:rs
Active(file):sInactive(file):�
SReclaimable:zY%s is missing from /proc/meminfo; using an approximation for calculating available memoryNz%s/zoneinfoslowrr9g@)
�get�KeyErrorr�argsrr�IOError�stripr��intr}�PAGESIZE�min)�memsrS�fallbackZlru_active_fileZlru_inactive_fileZslab_reclaimable�errr�Z
watermark_low�line�availZ	pagecacher?r?r@�calculate_avail_vmembs<��

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�rDt|�}|dk�r^d}|�d�n||k�rl|}t|||dd�}|�r�dd�	|�t
|�dk�r�dndf}tj|t
dd �t||||
||
||||	|�S)!a7Report virtual memory stats.
    This implementation mimics procps-ng-3.3.12, aka "free" CLI tool:
    https://gitlab.com/procps-ng/procps/blob/
        24fd2605c51fccc375ab0287cec33aa767f06718/proc/sysinfo.c#L778-791
    The returned values are supposed to match both "free" and "vmstat -s"
    CLI tools.
    �
%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�Zround_z6%s memory stats couldn't be determined and %s set to 0�, �was�werer9��
stacklevel)rrr}r�r�r�r�r�r�joinr��warnings�warn�RuntimeWarningrN)Zmissing_fieldsr�r�r�r�rOrSrVrWrXrTrUrYrRr�rQ�msgr?r?r@�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��}WnNt�y }
z4d
dt	|
�}t
j|tdd
�d}}
WYd}
~
n�d}
~
00|��d}}
|D]n}|�
d��r`t|�d�d�dd}n&|�
d��r�t|�d�d�dd}
|du�r4|
du�r4�qȐq4d
}|d7}t
j|tdd
�d}}
Wd�n1�s�0Yt�||||	||
�S)zReturn swap memory metrics.r�rr�rNs
SwapTotal:s	SwapFree:r�z	%s/vmstatz,'sin' and 'sout' swap memory stats couldn't z$be determined and were set to 0 (%s)r9r�spswpin� �spswpoutzbe determined and were set to 0)rrr}r�r��cextZ
linux_sysinforr��strr�r�r�r�rZsswap)r�r�r�r�rOrS�_Zunit_multiplierrRrQr�r��sinZsoutr?r?r@�swap_memory'sJ8
��
(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?r@r�or�zcpu_times.<locals>.<listcomp>)rr�rr�r}r�r��_fields)r�r�r�r�r?r?r@�	cpu_timescs*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?r@r��r�z!per_cpu_times.<locals>.<listcomp>N)
rr�rr�r�r}r�r�r�r�)r��cpusr�r�r�r��entryr?r?r@�
per_cpu_timesss
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�ro)r{�sysconf�
ValueErrorrr�lowerr��re�compilerr}�match)�numr�r��searchr?r?r@�cpu_count_logical�s$(

(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�add�readr�r�rr�r�r�r}r��sumr�)�ls�p1�p2rar��result�mappingZcurrent_infor��key�valuer?r?r@�cpu_count_cores�s6
2�
.rcCs�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}rZ	scpustats)r�Zctx_switchesZ
interruptsZsoft_interruptsr�Zsyscallsr?r?r@�	cpu_stats�s,


���$�rc	Cshg}tdt���B}|D],}|���d�r|�t|�dd�d��qWd�n1sZ0Y|S)z7Return current CPU frequency from cpuinfo if available.r�scpu mhz�:rN)rrr�r�r�r�r})r�r�r�r?r?r@�_cpu_get_cpuinfo_freq�s:rz'/sys/devices/system/cpu/cpufreq/policy0z$/sys/devices/system/cpu/cpu0/cpufreqcCs&t�}t�d�pt�d�}|jdd�d�g}tjj}t|�D]�\}}t|�t|�krd||d}nt||d�dd	�}|dur�t||d
�dd	�}|dur�d�	|�}t
|dd	�dkr�|�t�
d
d
d
��q>d}t|��t|�d}tt||d���d}	tt||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)rHr?r?r@�<lambda>�r�zcpu_freq.<locals>.<lambda>)r�i�Zscaling_cur_freqN�r�Zcpuinfo_cur_freqz$/sys/devices/system/cpu/cpu{}/onlinez0
r�z!can't find current frequency fileZscaling_max_freqZscaling_min_freq)rr��sortr{rar��	enumerater�r�formatrr�r�scpufreq�NotImplementedErrorr�)Z
cpuinfo_freqs�pathsr��pjoin�ira�currZonline_pathr�Zmax_Zmin_r?r?r@�cpu_freq�s8���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?r@r�#r�zcpu_freq.<locals>.<listcomp>)rr?r?r?r@rsc@seZdZdS)�_Ipv6UnsupportedErrorN)r<r=r>r?r?r?r@r.src@sZeZdZdZdd�Zdd�Zdd�Zedd	��Zeddd��Z	edd
d��Z
ddd�Zd
S)�NetConnectionsawA 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�inetZinet4Zinet6)�socket�AF_INET�SOCK_STREAM�AF_INET6�
SOCK_DGRAM�AF_UNIX�tmap�_procfs_path)�selfrrrrrr?r?r@�__init__>s$
�
zNetConnections.__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����)r�listr{�listdirr#r|rr!r��errno�EINVAL�ENAMETOOLONGrr�r�r�)r$r��inodesrb�inoder�r?r?r@�get_proc_inodesUs"
zNetConnections.get_proc_inodescCsFi}t�D]6}z|�|�|��Wq
tttfy>Yq
Yq
0q
|S�N)�pids�updater0rr!r )r$r.r�r?r?r@�get_all_inodesos
zNetConnections.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?�asciiNr(z>4Iz<4I)r}r�r�encoderr�
LITTLE_ENDIAN�	inet_ntop�base64�	b16decoder�struct�pack�unpackr�rrr�addr)r@�family�ip�portr?r?r@�decode_addresss4



��zNetConnections.decode_addressNccsN|�d�rtj�|�sdSt|���}|��t|d�D]�\}}z(|��dd�\
}}	}
}}}}}}}Wn$ty�t	d|||f��Yn0||vr�||d\}
}nd\}
}|dur�||
kr�q8q8|t
jkr�t|}nt
j}zt�|	|�}	t�|
|�}
Wnt�yYq8Yn0||||	|
||
fVq8Wd�n1�s@0YdS)z.Parse /proc/net/tcp* and /proc/net/udp* files.�6Nrr�z,error while parsing %s; malformed line %s %rr�Nr()r~r{ra�existsrr�rr}r��RuntimeErrorrr�TCP_STATUSESr�	CONN_NONErrDr)�filerA�type_r.�
filter_pidr��linenor�r��laddr�raddr�statusr/r�rbr?r?r@�process_inet�s8���



zNetConnections.process_inetc
cst|���}|��|D]�}|��}z|dd�\}}}}}}}	Wn.tynd|vrZYqtd||f��Yn0|	|vr�||	}
ndg}
|
D]`\}}|dur�||kr�q�q�t|�dkr�|dnd	}
t�t|��}d	}tj	}||||
|||fVq�qWd�n1�s0YdS)
zParse /proc/net/unix files.r�roz)error while parsing %s; malformed line %rrFNr�r(�)
rr�r}r�rHr�rZsocktype_to_enumr�rJ)rKrAr.rMr�r��tokensr�rLr/�pairsr�rbrarPrQr?r?r@�process_unix�s2
��

zNetConnections.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?r@r�r�z+NetConnections.retrieve.<locals>.<listcomp>z	%s/net/%s)rM)r"r�r�rr#r0r4r�rrrrRrWr�pconnZsconnr�r))r$�kindr�r.r�Z
proto_namerArLrar�rbrOrPrQZ	bound_pid�connr?r?r@�retrieves<
��

���zNetConnections.retrieve)N)N)N)r<r=r>�__doc__r%r0r4�staticmethodrDrRrWr\r?r?r?r@r2s
4)#rrcCs
t�|�S)z$Return system-wide open connections.)�_net_connectionsr\)rZr?r?r@�net_connections)sr`cCs�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/devNr9r5rr)	rr�	readlines�rfindrXr�r}�mapr�)r��lines�retdictr��colonr�r�Z
bytes_recvZpackets_recvZerrinZdropinZ_fifoinZ_frameinZ
_compressedinZ_multicastinZ
bytes_sentZpackets_sentZerroutZdropoutZ_fifooutZ_collisionsoutZ_carrieroutZ_compressedoutr?r?r@�net_io_counters.sH&
��

rgcCs�tjttjttjti}t���}i}|D]�}z&t	�
|�}t	�|�}t�|�\}}Wn<t
y�}z$|jtjkrr�nt|�WYd}~q(d}~00d�|�}	d|v}
t�|
|||||	�||<q(|S)z)Get NIC stats (isup, duplex, speed, mtu).N�,�running)r�ZDUPLEX_FULLr
ZDUPLEX_HALFrZDUPLEX_UNKNOWNrrg�keys�
cext_posixZ
net_if_mtuZnet_if_flagsZnet_if_duplex_speedr�r+ZENODEVrr�rZ	snicstats)Z
duplex_map�namesr�r�ZmtureZduplex�speedr�Zoutput_flagsZisupr?r?r@�net_if_stats]s*�



�
rnFcCs�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:r9r���rSrz!not sure how to interpret line %r)rrrar}r�r�rcr�)r�rdr�r�Zflenr��reads�reads_merged�rbytes�rtime�writes�
writes_merged�wbytes�wtimer�r_r?r?r@�read_procfs�s4&
�
��
�
�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*�walkrar�rr�r�r}�basenamercr�)�block�rootr��filesr�r�r�rsrtrurvrwrxryrzr_r?r?r@�
read_sysfs�s.��z$disk_io_counters.<locals>.read_sysfsror|zC%s/diskstats nor /sys/block filesystem are available on this system)r{rarGrrr��DISK_SECTOR_SIZE)Zperdiskr{r��genrer�r�rsrwruryrvrzrtrxr_r?r?r@�disk_io_counters�s0-����
r�c@s@eZdZdZddgZdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�RootFsDeviceFinderaFdisk_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?r@r%�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/partitionsr9r�rrr:�/dev/%s)	rrrar}r��isdigitr�r�r�)r$r�r�r�r�r�r�r?r?r@�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=r9r�)r�r�rr�r��
rpartition)r$rar�r�r�r?r?r@�ask_sys_dev_blocks

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��iglobrrr�r�r{rar�dirname)r$�needler�rKr��datar�r?r?r@�ask_sys_class_blocks

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�|SdSr1)	r�r�r�rr�r�r{rarG)r$rar�r?r?r@�finds$zRootFsDeviceFinder.findN)
r<r=r>r]�	__slots__r%r�r�r�r�r?r?r?r@r��s
	r�cCs4t�}t�}|s�td|��\}|D]F}|��}|�d�sH|�|���q"|�d�d}|dkr"|�d�q"Wd�n1s~0Y|dkr�tj�	d�r�tj�
d�}ntj�
d	|�}g}t�|�}|D]b}	|	\}
}}}|
d
kr�d}
|
dvr�t
���p�|
}
|�s|
r�||v�rq�t�|
|||�}
|�|
�q�|S)
z8Return mounted disk partitions as a list of namedtuples.z%s/filesystemsZnodev�	rZzfsNr�z	/etc/mtabz%s/self/mounts�nonerT)z	/dev/rootZrootfs)r�rrr�r�r�r}r{ra�isfile�realpathr��disk_partitionsr�r�rZ	sdiskpartr�)rZfstypesr�r�r�ZfstypeZmounts_path�retlistZ
partitions�	partitionZdeviceZ
mountpoint�opts�ntupler?r?r@r�5s8
*
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|���}	Wntttfy�YqzYn0t|ddd
�}
t|ddd
�}t|ddd
���}|
du�rDzt|
�d	}
Wnt�yBd}
Yn0|du�rxzt|�d	}Wnt�yvd}Yn0||	�
|||
|f�qz|�sXt�d�}tt|��}|D�]�}z<t
j�|d�}tt|��d	}t
j�|d�}t|���}	WnBtttf�y4}
z"t|
�WYd}
~
�q�WYd}
~
n
d}
~
00t�|d�}tdd�|D��}d}d}
|D]�}t
j�||d�}t|dd
���}|dk�r�tt
j�||d�dd
�}n$|dk�r�tt
j�||d�dd
�}
|
du�rzt|
�d	}
Wnt�yd}
Yn0|du�rbzt|�d	}Wnt�y8d}Yn0�qb||	�
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?r@r�tr�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�Z_maxNrZ_crit�_labelrTz /sys/class/thermal/thermal_zone*�temp�typez/trip_point*cSs,g|]$}d�tj�|��d�dd���qS)r�rr:)r�r{rarr})r��pr?r?r@r��s��_type�critical�_temp�high)�collectionsrr)r��extend�sortedr�r�r��subr�r�rr{rar�r�rr�r�r�r�r�dict)r��	basenamesZ
basenames2�replr�Zaltname�baserar��	unit_namer�r��labelr�Z
trip_pathsZtrip_pointsZ
trip_pointZ	trip_typer?r?r@�sensors_temperaturesas�

�

	






$�
�
�


r�cCs�t�t�}t�d�}|s"t�d�}ttdd�|D���}|D]�}ztt|d��}Wn<tt	fy�}z t
|�WYd}~q<WYd}~n
d}~00ttj
�tj
�|�d����}t|dd	d
���}||�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?r@r��r�z sensors_fans.<locals>.<listcomp>r�Nr�r�rTr)r�rr)r�r�r�r�rr�r�rrr{rar�r�r�r�rZsfanr�)r�r�r�r�r�r�r�r?r?r@�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}n6t	|ddd��
���}
|
dk�r>d}n|
dv�rLd}|�rZtj
}nt|du�r�|du�r�zt||d�}Wnt�y�tj}Yn0n.|du�r�t|d�}|dk�r�tj}ntj}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	sP|D]F}t|�d�}|�krzt|�WStyH|��YS0qdS)zvAttempt to read the content of multiple files which may
        not exist. If none of them exist return None.
        rN)rr�r�r�)rrar���nullr?r@�
multi_bcat�sz#sensors_battery.<locals>.multi_bcatcSs&g|]}|�d�sd|��vr|�qS)ZBATZbattery)r�r�r�r?r?r@r�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	/capacityr(rz
AC0/onlinez	AC/onlinerz/statusrTZdischargingF)Zcharging�fullTi�<)�objectr{r*�POWER_SUPPLY_PATHrar�r��ZeroDivisionErrorr�rr�r�rZPOWER_TIME_UNLIMITEDZPOWER_TIME_UNKNOWNZsbattery)r�Zbatsr�Z
energy_nowZ	power_nowZenergy_fullZ
time_to_emptyrQZ
power_pluggedZonlinerQZsecsleftr?r�r@�sensors_battery�sZ
��





r�c	CsHg}t��}|D]2}|\}}}}}t�||p.d|||�}|�|�q|S)z:Return currently connected users as a list of namedtuples.N)r��usersrZsuserr�)	r�Zrawlist�itemrr�tty�hostnameZtstampr��ntr?r?r@r�Us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_TIMErH)rar�r�r�r?r?r@�	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?r@r�tr�zpids.<locals>.<listcomp>)r{r*r"rr?r?r?r@r2rsr2c	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��EnvironmentErrorr2)r�rar�r�Ztgidr?r?r@r�ws



.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�)r9r)	rr2rr�rr!rbr}r�)r�r�r�r�r��rparZdset�ppidr?r?r@�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��Ynhty^|��t|j|j��YnBty�|��tj	�
d|j|jf�s�t|j|j���Yn0dS)N�%s/%s)r r
r��_namer!�_raise_if_zombierrr{rarGr#)r$r��kwargs��funr?r@�wrapper�sz wrap_exceptions.<locals>.wrapper)�	functools�wraps)r�r�r?r�r@�wrap_exceptions�sr�c@s�eZdZdZgd�Zdd�Zdd�Zdd�Zd	d
�Ze	e
dd���Ze	e
d
d���Ze	e
dd���Z
dd�Zdd�Ze	dd��Ze	dd��Ze	dd��Ze	dd��Ze	dd��Zej�de���r�e	d d!��Ze	d"d#��Ze	d$d%��Ze	ddd'd(��Ze	d)d*��Ze	d+d,��Ze�se �rVd-d.�Z!e	e"�#d/�e"�#d0�e"�#d1�fd2d3��Z$e	d4d5��Z%neZ%e �rle	d6d7��Z&e	d8d9��Z'e	e"�#d:�fd;d<��Z(e	e"�#d=�fd>d?��Z)e	d@dA��Z*e	dBdC��Z+e	dDdE��Z,e-�r�e	dFdG��Z.e"�#dH�fdIdJ�Z/e	dKdL��Z0e1�re	dMdN��Z2e	dOdP��Z3e4d&u�r.e	dedQdR��Z5e	dSdT��Z6e	dUdV��Z7e	dfdXdY��Z8e	dZd[��Z9e	d\d]��Z:e	e"�#d^�fd_d`��Z;e	e"�#da�fdbdc��Z<d&S)g�ProcesszLinux process implementation.)�_cacher��_ppidr#r�cCs||_d|_d|_t�|_dSr1)r�r�r�rr#)r$r�r?r?r@r%�szProcess.__init__c	Cs\ztd|j|jf�}Wnttfy0YdS0|�d�}||d|d�}|dkSdS)Nr�Fr�r9r:�Z)rr#r�r�r�rb)r$r�r�rQr?r?r@�
_is_zombie�s
zProcess._is_zombiecCs|��rt|j|j|j��dSr1)r�rr�r�r��r$r?r?r@r��szProcess._raise_if_zombiecCst�d|j|jf�dS)z+Raise NSP if the process disappeared on us.r�N)r{r}r#r�r�r?r?r@�_raise_if_not_alive�szProcess._raise_if_not_alivecCs�td|j|jf�}|�d�}||�d�d|�}||dd���}i}||d<|d|d	<|d|d
<|d|d<|d
|d<|d|d<|d|d<|d|d<|d|d<|d|d<z|d|d<Wn"ty�td�d|d<Yn0|S)aYParse /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 subtract 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�r��(rr9Nr�rrQr�r��ttynr��utime��stime�
�children_utimerq�children_stime��create_time�$�cpu_num�'�blkio_ticksz&can't get blkio_ticks, set iowait to 0)rr#r�rbr�r}�
IndexErrorr)r$r�r�r�r�r�r?r?r@�_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?r@�_read_status_fileszProcess._read_status_filecCsDtd|j|jf��}|����Wd�S1s60YdS)Nz%s/%s/smaps)rr#r�r�r�r�r?r?r@�_read_smaps_fileszProcess._read_smaps_filecCs(|j�|�|j�|�|j�|�dSr1)r�Zcache_activater�r�r�r?r?r@�
oneshot_enter szProcess.oneshot_entercCs(|j�|�|j�|�|j�|�dSr1)r�Zcache_deactivater�r�r�r?r?r@�oneshot_exit%szProcess.oneshot_exitcCs|��d}trt|�}|S)Nr�)r�rr)r$r�r?r?r@r�*szProcess.namec	CsZztd|j|jf�WSttfyT|��tj�d|j|jf�rNYdS�Yn0dS)Nz	%s/%s/exer�rT)	r|r#r�rr!r�r{ra�lexistsr�r?r?r@�exe2szProcess.execCs�td|j|jf��}|��}Wd�n1s20Y|sL|��gS|�d�rZdnd}|�|�rt|dd�}|�|�}|dkr�t|�dkr�d|vr�|�d�}|S)Nz
%s/%s/cmdlinerwror(r)rr#r�r�r�r~r}r�)r$r�r��sep�cmdliner?r?r@r�?s&


zProcess.cmdlinecCsDtd|j|jf��}|��}Wd�n1s20Yt|�S)Nz
%s/%s/environ)rr#r�r�r)r$r�r�r?r?r@�environYs&zProcess.environcCs<t|��d�}t��}z
||WSty6YdS0dS)Nr�)r�r�rZget_terminal_mapr�)r$Ztty_nrr"r?r?r@�terminal_s
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
|j
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�rHrpr�r�)r$�fnamer�r�r�r�r�r�r?r?r@�io_countersks8

,���zProcess.io_counterscCsh|��}t|d�t}t|d�t}t|d�t}t|d�t}t|d�t}t|||||�S)Nr�r�r�r�r�)r�r�r�rq)r$r�r�r�r�r�rvr?r?r@r��szProcess.cpu_timescCst|��d�S)zWhat CPU the process is on.r��r�r�r�r?r?r@r��szProcess.cpu_numNcCst�|j||j�Sr1)rZwait_pidr�r�)r$�timeoutr?r?r@�wait�szProcess.waitcCs&t|��d�}tpt�}|t|S)Nr�)r�r�r�r�r�)r$�ctimeZbtr?r?r@r��s
zProcess.create_timec	Csttd|j|jf��<}dd�|����dd�D�\}}}}}}}Wd�n1sV0Yt|||||||�S)Nz%s/%s/statmcss|]}t|�tVqdSr1)r�r�r�r?r?r@�	<genexpr>�sz&Process.memory_info.<locals>.<genexpr>rS)rr#r�r�r}rf)	r$r�ZvmsrlrX�text�libr�Zdirtyr?r?r@�memory_info�s

�2zProcess.memory_infocCs�d}}}td�|j|j���|}|D]f}|�d�rN|t|��d�d7}q&|�d�rnt|��d�d}q&|�d�r&t|��d�d}q&Wd�n1s�0Y|||fS)Nrz{}/{}/smaps_rollupsPrivate_rr��Pss:�Swap:)rr	r#r�r�r�r})r$rhrirjr�r�r?r?r@�_parse_smaps_rollup�s	�


4zProcess._parse_smaps_rollups\nPrivate.*:\s+(\d+)s\nPss\:\s+(\d+)s\nSwap\:\s+(\d+)cCsZ|��}ttt|�|���d}ttt|�|���d}ttt|�|���d}|||fS)Nr�)r�r�rcr��findall)r$Z_private_reZ_pss_reZ_swap_reZ
smaps_datarhrirjr?r?r@�_parse_smaps�s
zProcess._parse_smapsc	Csftr>z|��\}}}WqLttfy:|��\}}}YqL0n|��\}}}|��}t||||f�Sr1)�HAS_PROC_SMAPS_ROLLUPr	r!rrrrg)r$rhrirjZ	basic_memr?r?r@�memory_full_info�szProcess.memory_full_infocCs^dd�}|��}|s |��gS|�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
}|�|�qH|S)aQReturn 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�)rd�
current_blockr�r�r�r?r?r@�
get_blockss"��z'Process.memory_maps.<locals>.get_blocks�
rNrrTz[anon]rxrysRss:sSize:rs
Shared_Clean:s
Shared_Dirty:sPrivate_Clean:sPrivate_Dirty:sReferenced:s
Anonymous:r)r�r�r}rr�rrr�r~rr�r�)r$rr�rdr��
first_liner�headerZhfieldsr@Zperms�_offset�_devZ_inoderar�r?r?r@�memory_mapssP


�









�zProcess.memory_mapscCstd|j|jf�S)Nz	%s/%s/cwd)r|r#r�r�r?r?r@�cwdRszProcess.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)r�r
rr#r�rZpctxswr�)r$Z	_ctxsw_rer�Zctxswr?r?r@�num_ctx_switchesVs

��zProcess.num_ctx_switchessThreads:\t(\d+)cCs|��}t|�|�d�S�Nr)r�r�r
)r$Z_num_threads_rer�r?r?r@�num_threadseszProcess.num_threadsc
Cst�d|j|jf�}|��g}d}|D]�}d|j|j|f}z8t|��}|����}Wd�n1sl0YWntt	fy�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�r9r�r�r�)r{r*r#r�rrr�r�rr!r�r}r�r�rZpthreadr�r�r�)r$Z
thread_idsr��
hit_enoent�	thread_idr�r��str�r�r�r�r?r?r@�threadsms2�
.

zProcess.threadscCst�|j�Sr1)rk�getpriorityr�r�r?r?r@�nice_get�szProcess.nice_getcCst�|j|�Sr1)rk�setpriorityr�)r$r�r?r?r@�nice_set�szProcess.nice_setcCst�|j�Sr1)r�r4r�r�r?r?r@�cpu_affinity_get�szProcess.cpu_affinity_getsCpus_allowed_list:\t(\d+)-(\d+)cCsV|��}|�|�}|r@ttt|dd�t|dd�d��Stttt����SdS)Nrr)r�r
r)�ranger�r�r�)r$�_rer�r�r?r?r@�_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�rzr+r,r'�tupler%r�r�)r$r�r�Z
eligible_cpusZall_cpus�cpur?r?r@�cpu_affinity_set�s(����zProcess.cpu_affinity_setcCs,t�|j�\}}tdur t|�}t�||�Sr1)r�r3r��enumr;rZpionice)r$�ioclassr�r?r?r@�
ionice_get�szProcess.ionice_getcCsT|durd}|r(|ttfvr(td|��|dks8|dkrDd}t|��t�|j||�S)Nrz%r ioclass accepts no valuerSzvalue not in 0-7 range)r'r$r�r�Zproc_ioprio_setr�)r$r,r�r�r?r?r@�
ionice_set�szProcess.ionice_setc
Cs�|jdkrd}t|��zL|dur.t|j|�WSt|�dkrRddt|�}t|��t|j||�Wn:ty�}z"|jtjkr�|���WYd}~n
d}~00dS)Nrz)can't use prlimit() against PID 0 processr9z'second argument must be a (soft, hard) z
tuple, got %s)	r�r�r�r�rXr�r+ZENOSYSr�)r$r�r�r�r�r?r?r@�rlimit�s"

��zProcess.rlimitcCs$|��d}tr|��}t�|d�S)NrQ�?)r�rr�
PROC_STATUSESr�)r$�letterr?r?r@rQ�szProcess.statusc
Cs�g}t�d|j|jf�}d}|D�]b}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�s20YWnttf�yZd}Yq"0t|
�}t|t|�t|	�||
�}|�|�q"|�r�|��|S)	Nr&Fr'Tr�z%s/%s/fdinfo/%srr�)r{r*r#r�r|rr!r�r+r,r-rr�rrr�r�r}r�r`r�r�)
r$r�r�rrbrKrar�r��posrerdr�r?r?r@�
open_files�sJ
�
:
�zProcess.open_filesrcCst�||j�}|��|Sr1)r_r\r�r�)r$rZr�r?r?r@r`/	szProcess.net_connectionscCstt�d|j|jf��S)Nr&)r�r{r*r#r�r�r?r?r@�num_fds5	szProcess.num_fdscCst|��d�S)Nr�r�r�r?r?r@r�9	szProcess.ppidsUid:\t(\d+)\t(\d+)\t(\d+)cCs6|��}|�|�d\}}}t�t|�t|�t|��Sr)r�r
rZpuidsr�)r$Z_uids_rer��real�	effective�savedr?r?r@�uids=	szProcess.uidssGid:\t(\d+)\t(\d+)\t(\d+)cCs6|��}|�|�d\}}}t�t|�t|�t|��Sr)r�r
rZpgidsr�)r$Z_gids_rer�r6r7r8r?r?r@�gidsC	szProcess.gids)N)N)r)=r<r=r>r]r�r%r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r{rarG�getpidr�r�r�rr�rr�HAS_PROC_SMAPSr	r�r�rr
rrrrrr!r#�HAS_CPU_AFFINITYr$r'r*�HAS_PROC_IO_PRIORITYr-r.r�r/rQr4r`r5r�r9r:r?r?r?r@r��s�%




	
 
	



�
K
�



�







3

r�)N)r)F)F)�r]�
__future__rr;r�r+r�r�r{r�rr=�sysr�rrrTrrrr�r	rkr
rrr
rrrrrrrrrrrrrrrrZ_compatrrr r!r"r#r+Z__extra__all__r�rarGr;r<r�hasattrr>r=r�r�Zgetpagesizer�r��	byteorderr9r��	AF_PACKETr8�IntEnumr�r7r$r%r&r'r;�globalsr3�__members__ZSTATUS_RUNNINGZSTATUS_SLEEPINGZSTATUS_DISK_SLEEPZSTATUS_STOPPEDZSTATUS_TRACING_STOPZ
STATUS_ZOMBIEZSTATUS_DEADZSTATUS_WAKE_KILLZ
STATUS_WAKINGZSTATUS_IDLEZ
STATUS_PARKEDr1r(r)r*r+r,r-r.r/r0r1r2rIrNrZr`rfr�rgrkr�rnrprqr|r�r�r��	Exceptionr�r�r��resource�ImportErrorr��CDLLr�r��dirr�r�r�r�r�r�rrrrZnet_if_addrsrrr_r`rgrn�
disk_usager�r�r�r�r�r�r�r�r2r�r�r�r�r?r?r?r@�<module>sb






�
�����
���

(

�
@<+
�
)u
/"
hK
,v_