/ lib / psutil / _pslinux.pyc
_pslinux.pyc
  1  o

  2  #��c=Z�
@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
  3  Z
  4  ddlZddlZddl
Z
ddlZddlmZddlmZddlmZddlmZdd	lmZdd
  5  lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!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,m0Z0dd#l,m1Z1dd$l,m2Z2ej3d%k�rddl4Z4ndZ4gd&�Z5d'Z6ej7�8d(e�9��Z:ej7�8d)e�9��Z;e<ed*�Z=e<ed+�Z>e�?d,�Z@e�A�ZBdaCejDd-kZEd.ZFe4du�rDe
  6  jGZHne4�Id/d0eJe
  7  jG�i�ZKeKjHZHe4du�r`dZLdZMd1ZNd2ZOnGd3d4�d4e4jI�ZPeQ��RePjS�ejTejUejVejWejXejYejZejZej[ej\ej]ej^d5�Z_ej`ejaejbejcejdejeejfejgejhejiejjd6�Zked7gd8��Zled9gd:��Zmed;gd<��Zned=d>�Zoed?eojpd@�ZqedAgdB��ZredCdDdE�serjp��ZtedFgdG��ZuedHgdI��ZvdJdK�ZwdLdM�ZxdNdO�Zye$dPdQ��ZzzezdR�Wne{�ye
�|�edSdT�dUdUdU�a}YnwdZ~zddVlm~Z~Wn e��y@ddl�Z�e�j�ddWdX�Z�e<e�dY��r>d�dZdY�Z~Ynwe~du�rRe5��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�ej7�8do��s�ej7�8dp��r�dqdr�Z�ndsdr�Z�ej�Z�Gdtdu�due{�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�e��Z�dS)�zLinux platform implementation.�)�divisionN)�defaultdict)�
  8  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)�
  9  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�
 10  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_getZ
 11  SC_CLK_TCK�littlei�
AddressFamily�AF_LINK�r$c@seZdZdZdZdZdZdS)�
 12  IOPriorityrrr;r$N)�__name__�
 13  __module__�__qualname__r'r(r)r*�r@r@��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\psutil\_pslinux.pyr<vs
 14  r<)�R�S�D�T�t�Z�X�x�K�W�I�P)�01�02�03�04�05Z06Z07Z08Z09Z0AZ0B�svmem)�total�	available�percent�used�free�active�inactive�buffers�cached�shared�slab�sdiskio)	�
 15  read_count�write_count�
 16  read_bytes�write_bytes�	read_time�
 17  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)rh�rss�sizerpZshared_cleanZshared_dirtyZ
private_cleanZ
private_dirtyZ
 18  referenced�	anonymousrq�	pmmap_extzaddr perms � �pio)r`rarbrcZ
 19  read_charsZwrite_chars�	pcputimes)�user�system�
children_user�children_system�iowaitcCsLt|t�s	J|��t�|�}|�d�d}|�d�r$t|�s$|dd�}|S)zWrapper around os.readlink().�r�
 20   (deleted)N�����)�
 21  isinstancer#�os�readlink�split�endswithr)rhr@r@rAr��s
 22  r�cCsXtjdtjdtjdi}||tjtjBtjB@}|tj@r$|�ddd�}|�dd�}|S)zZConvert file's open() flags into a readable string.
 23      Used by Process.open_files().
 24      �r�wzw+�arzr+)r��O_RDONLY�O_WRONLY�O_RDWR�O_APPEND�replace)rlZ	modes_maprkr@r@rA�file_flags_to_mode�s
 25  r�cCs4|�dd�}d}|rd|}nd|}t�|tj�S)z�Return True if the given name refers to a root device (e.g.
 26      "sda", "nvme0n1") as opposed to a logical partition (e.g.  "sda1",
 27      "nvme0n1p1"). If name is a virtual device (e.g. "loop1", "ram")
 28      return True.
 29      �/�!Tz
/sys/block/%sz/sys/block/%s/device)r�r��access�F_OK)�nameZincluding_virtualrhr@r@rA�is_storage_device�s
 30  
 31  r�cCs�td|��}|����dd�}Wd�n1swYgd�}t|�}|dkr1|�d�|dkr:|�d�|d	krC|�d
 32  �td|�adS)z�Set a namedtuple of variable fields depending on the CPU times
 33      available on this Linux kernel version which may be:
 34      (user, nice, system, idle, iowait, irq, softirq, [steal, [guest,
 35       [guest_nice]]])
 36      Used by cpu_times() function.
 37      �%s/statrN)rz�nicer{�idler~�irqZsoftirq��steal�	�guest�
 38 39  guest_nice�	scputimes)r�readliner��len�appendrr�)�procfs_path�f�values�fieldsZvlenr@r@rA�set_scputimes_ntuples	�
 40  
 41  
 42  r��/procr�zuser system idle�)�prlimitT)�	use_errnor�cCs�Gdd�dtj�}|�}|durt�||dt�|��}n|�}|d|_|d|_t�||t�|�t�|��}|dkrGt��}t|t	�
 43  |���|j|jfS)Nc@s eZdZdejfdejfgZdS)zprlimit.<locals>.StructRlimit�rlim_cur�rlim_maxN)r=r>r?�ctypes�
 44  c_longlong�_fields_r@r@r@rA�StructRlimit9s�r�rr)r��	Structure�libcr��byrefr�r��	get_errno�OSErrorr��strerror)�pid�	resource_�limitsr��current�ret�new�errnor@r@rAr�8s
 45  
 46  �cCs"g|]
}|�d�r|��r|�qS)�RLIM)�
 47  startswith�isupper��.0rIr@r@rA�
 48  <listcomp>Qs"r�cCs|d}||�dd�}z|d}|d}|d}Wnty%|YSwz	tdt��}Wnty:|YSwd}|� |D]}|��}|�d�rW|t|��d	�7}qBWd
 49  �n1sbwY|t	9}||}	||}
 50  |
 51  t
 52  |
 53  d|�8}
 54  |	|
 55  7}	|	|t
 56  |d|�7}	t|	�S)
a�Fallback for kernels < 3.14 where /proc/meminfo does not provide
 57      "MemAvailable:" column, see:
 58      https://blog.famzah.net/2014/09/24/
 59      This code reimplements the algorithm outlined here:
 60      https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
 61          commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773
 62  
 63      XXX: on recent kernels this calculation differs by ~1.5% than
 64      "MemAvailable:" as it's calculated slightly differently, see:
 65      https://gitlab.com/procps-ng/procps/issues/42
 66      https://github.com/famzah/linux-memavailable-procfs/issues/2
 67      It is still way more realistic than doing (free + cached) though.
 68      �MemFree:�Cached:rs
Active(file):sInactive(file):�
SReclaimable:z%s/zoneinfoslowrNr;g@)�get�KeyErrorrr�IOError�stripr��intr��PAGESIZE�min)�memsrX�fallbackZlru_active_fileZlru_inactive_fileZslab_reclaimabler�Z
watermark_low�line�availZ	pagecacher@r@rA�calculate_avail_vmemYs<��
 69  ���r�cCs�g}i}tdt���}|D]}|��}t|d�d||d<qWd�n1s+wY|d}|d}z|d}WntyNd}|�d	�Ynwz|d
 70  }Wntyed}|�d�Yn	w||�dd�7}z|d
}	Wn ty�z|d}	Wnty�d}	|�d�YnwYnwz|d}
 71  Wnty�d}
 72  |�d�Ynwz|d}Wn(ty�z|d|d|d}Wnty�d}|�d�YnwYnwz|d}Wnty�d}Ynw||||}
|
dkr�||}
z|d}Wnt�yt|�}Ynw|dk�rd}|�d�||k�r%|}t|||dd�}|�rIdd�	|�t
 73  |�dk�r?dndf}t�|t
�t||||
||
 74  ||||	|�S)a�Report virtual memory stats.
 75      This implementation matches "free" and "vmstat -s" cmdline
 76      utility values and procps-ng-3.3.12 source was used as a reference
 77      (2016-09-18):
 78      https://gitlab.com/procps-ng/procps/blob/
 79          24fd2605c51fccc375ab0287cec33aa767f06718/proc/sysinfo.c
 80      For reference, procps-ng-3.3.10 is the version available on Ubuntu
 81      16.04.
 82  
 83      Note about "available" memory: up until psutil 4.3 it was
 84      calculated as "avail = (free + buffers + cached)". Now
 85      "MemAvailable:" column (kernel 3.14) from /proc/meminfo is used as
 86      it's more accurate.
 87      That matches "available" column in newer versions of "free".
 88 89  %s/meminfor�rNs	MemTotal:r�sBuffers:r[r�r\r�sShmem:s
 90  MemShared:r]sActive:rYs	Inactive:sInact_dirty:sInact_clean:sInact_laundry:rZsSlab:s
MemAvailable:rU��round_z6%s memory stats couldn't be determined and %s set to 0�, �was�were)rrr�r�r�r�r�r�r�joinr��warnings�warn�RuntimeWarningrS)Zmissing_fieldsr�r�r�r�rTrXr[r\r]rYrZr^rWr�rV�msgr@r@rA�virtual_memory�s�����	����������
 91  �	�
 92  
 93  
 94  ��r�c
 95  Cs�i}tdt���}|D]}|��}t|d�d||d<qWd�n1s)wYz
 96  |d}|d}WntyTt��\}}}}}}}||9}||9}Ynw||}t||dd�}	z	td	t��}Wn"ty�}
 97  zd
 98  t	|
 99  �}t
100  �|t�d}}
WYd}
101  ~
102  n[d}
103  ~
104  ww|�Ld}}
|D]1}|�
d�r�t|�d�d�d
d}n|�
d�r�t|�d�d�d
d}
|dur�|
dur�n
q�d}t
105  �|t�d}}
Wd�n1s�wYt�||||	||
�S)zReturn swap memory metrics.r�rr�rNs
106  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�rTrX�_Zunit_multiplierrWrV�errr��sin�soutr@r@rA�swap_memorysV������
107  
108  ���r�cCsrt�}t|�td|��}|����}Wd�n1swY|dttj�d�}dd�|D�}t|�S)z�Return a named tuple representing the following system-wide
109      CPU times:
110      (user, nice, system, idle, iowait, irq, softirq [steal, [guest,
111       [guest_nice]]])
112      Last 3 fields may not be available on all Linux kernel versions.
113      r�NrcS�g|]}t|�t�qSr@��float�CLOCK_TICKSr�r@r@rAr�M�zcpu_times.<locals>.<listcomp>)rr�rr�r�r�r��_fields)r�r�r�r�r@r@rA�	cpu_timesAs�r�cCs�t�}t|�g}td|��7}|��|D]&}|�d�r<|��}|dttj�d�}dd�|D�}t|�}|�	|�q|Wd�S1sIwYdS)zfReturn a list of namedtuple representing the CPU times
114      for every CPU available on the system.
115      r�scpurcSr�r@r�r�r@r@rAr�_r�z!per_cpu_times.<locals>.<listcomp>N)
116  rr�rr�r�r�r�r�r�r�)r��cpusr�r�r�r��entryr@r@rA�
per_cpu_timesQs
117  
118  �$�r�cCs�zt�d�WStyvd}tdt���}|D]
}|���d�r&|d7}qWd�n1s1wY|dkrkt�d�}t	dt���}|D]}|�
119  d	�d}|�|�r[|d7}qIWd�n1sfwY|dkrrYdS|YSw)
120  z0Return the number of logical CPUs in the system.�SC_NPROCESSORS_ONLNr�
121  %s/cpuinfos	processorrNzcpu\dr�rw)r��sysconf�
122  ValueErrorrr�lowerr��re�compilerr��match)�numr�r��searchr@r@rA�cpu_count_logicales2���
123  
124  ����r�c
125  Cs.t�}d}d}t�|�pt�|�D]}t|��}|�|�����Wd�n1s+wYqt|�}|dkr;|Si}i}tdt���?}|D]4}|����}|sjz
126  |d||d<Wn	t	yfYnwi}qI|�
127  d�r}|�d	d
128  �\}	}
129  t|
130  �||	<qIWd�n1s�wYt
|���}|p�dS)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)rrs	:r)�set�globr�add�readr�r�rr�r�r�r�r��sumr�)�ls�p1�p2rhr��result�mappingZcurrent_infor��key�valuer@r@rA�cpu_count_cores�s@
131  ����
132  ���rcCs�tdt���J}d}d}d}|D]9}|�d�r t|��d�}n|�d�r.t|��d�}n
|�d�r;t|��d�}|durI|durI|durInqWd�n1sTwYd}t�||||�S)z*Return various CPU stats as a named tuple.r�Nsctxtrsintrssoftirqr)rrr�r�r�r�	scpustats)r��ctx_switches�
133  interrupts�soft_interruptsr��syscallsr@r@rA�	cpu_stats�s(
134  
135  
136  ���rc	Csjg}tdt���"}|D]}|���d�r"|�t|�dd�d��qWd�|S1s.wY|S)z<Return current CPU frequency from cpuinfo if available.
137      r�scpu mhz�:rN)rrr�r�r�r�r�)r�r�r�r@r@rA�_cpu_get_cpuinfo_freq�s��
138  ��rz'/sys/devices/system/cpu/cpufreq/policy0z$/sys/devices/system/cpu/cpu0/cpufreqc	Cs�t�}t�d�pt�d�}|jdd�d�g}tjj}t|�D]W\}}t|�t|�kr2||d}n	t||d�dd	�}|durPt||d
139  �dd	�}|durPt	d��t
140  |�d}t
141  t||d���d}t
142  t||d
���d}|�t�
|||��q|S)z�Return frequency metrics for all CPUs.
143          Contrarily to other OSes, Linux updates these values in
144          real-time.
145          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>��zcpu_freq.<locals>.<lambda>)ri�Zscaling_cur_freqN�r�Zcpuinfo_cur_freqz!can't find current frequency fileZscaling_max_freqZscaling_min_freq)rr�sortr�rhr��	enumerater�r�NotImplementedErrorr�r�r�scpufreq)	Z
cpuinfo_freqs�pathsr��pjoin�irh�curr�max_�min_r@r@rA�cpu_freq�s,
146  ��r%cCsdd�t�D�S)z}Alternate implementation using /proc/cpuinfo.
147          min and max frequencies are not available and are set to None.
148          cSsg|]	}t�|dd��qS)r�)rrr�r@r@rAr���zcpu_freq.<locals>.<listcomp>)rr@r@r@rAr%�sc@seZdZdS)�_Ipv6UnsupportedErrorN)r=r>r?r@r@r@rAr'�sr'c@sZeZdZdZdd�Zdd�Zdd�Zedd	��Zeddd��Z	edd
d��Z
149  ddd�Zd
150  S)�ConnectionsawA wrapper on top of /proc/net/* files, retrieving per-process
151      and system-wide open connections (TCP, UDP, UNIX) similarly to
152      "netstat -an".
153  
154      Note: in case of UNIX sockets we're only able to determine the
155      local endpoint/path, not the one it's connected to.
156      According to [1] it would be possible but not easily.
157  
158      [1] http://serverfault.com/a/417946
159      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)�tcp4r*r+�udp4r,r-�inet�inet4�inet6)�socket�AF_INET�SOCK_STREAM�AF_INET6�
160  SOCK_DGRAM�AF_UNIX�tmap�_procfs_path)�selfr/r*r0r,r-r@r@rA�__init__s$
161  �
162  
zConnections.__init__cCs�tt�}t�d|j|f�D]\}ztd|j||f�}Wn3ttfy'YqtyO}z|j	t	j
163  kr:WYd}~q|j	t	jkrJt|�WYd}~q�d}~ww|�
d�rj|dd�dd�}||�|t|�f�q|S)N�%s/%s/fd�%s/%s/fd/%szsocket:[r������)r�listr��listdirr;r�rr!r�r��EINVAL�ENAMETOOLONGrr�r�r�)r<r��inodesri�inoder�r@r@rA�get_proc_inodes%s(��
164  
165  �zConnections.get_proc_inodescCs@i}t�D]}z
166  |�|�|��WqtttfyYqw|S�N)�pids�updaterGrr!r )r<rEr�r@r@rA�get_all_inodes?s
167  �	zConnections.get_all_inodesc	Cs�|�d�\}}t|d�}|sdStr|�d�}|tjkr7tr-t�|t�	|�ddd��}nFt�|t�	|��}n<t�	|�}z)trRt�tj
168  tjdgt�
d|��R��}nt�tj
169  tjdgt�
d|��R��}Wn
tyrt�sqt��wt�||�S)	a�Accept an "ip:port" address as displayed in /proc/net/*
170          and convert it into a human readable form, like:
171  
172          "0500000A:0016" -> ("10.0.0.5", 22)
173          "0000000000000000FFFF00000100007F:9E49" -> ("::ffff:127.0.0.1", 40521)
174  
175          The IP address portion is a little or big endian four-byte
176          hexadecimal number; that is, the least significant byte is listed
177          first, so we need to reverse the order of the bytes to convert it
178          to an IP address.
179          The port is represented as a two-byte hexadecimal number.
180  
181          Reference:
182          http://linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html
183          �:�r@�asciiNr@z>4Iz<4I)r�r�r�encoder4r5�
LITTLE_ENDIAN�	inet_ntop�base64�	b16decoder7�struct�pack�unpackr�rr'r�addr)rW�family�ip�portr@r@rA�decode_addressOs8
184  
185  
186  
187  ����zConnections.decode_addressNccsB�|�d�rtj�|�sdSt|���}|��t|d�D]r\}}z|��dd�\
188  }}	}
189  }}}}}}}WntyDt	d|||f��w||vrR||d\}
}nd\}
}|dur_||
kr_q|t
190  jkrit|}nt
j}zt�|	|�}	t�|
191  |�}
192  Wn	ty�Yqw||||	|
193  ||
fVqWd�dS1s�wYdS)z.Parse /proc/net/tcp* and /proc/net/udp* files.�6Nrr�z,error while parsing %s; malformed line %s %rr�Nr@)r�r�rh�existsrr�rr�r��RuntimeErrorr4r6�TCP_STATUSESr�	CONN_NONEr(r[r')�filerX�type_rE�
194  filter_pidr��linenor�r��laddr�raddr�statusrFr�rir@r@rA�process_inet�sB�
195  ����
196  
197  ��"�zConnections.process_inetc
198  cs�t|��z}|��|D]j}|��}z|dd�\}}}}}}}	Wnty6d|vr.Yqtd||f��w|	|vr@||	}
199  ndg}
200  |
201  D]0\}}|durR||krRqEt|�dkr]|d}
nd	}
t�t|��}d	}tj	}||||
|||fVqEqWd�dS1s�wYdS)
202  zParse /proc/net/unix files.r�rwz)error while parsing %s; malformed line %rr]Nr�r@�)
203  rr�r�r�r_r�r�socktype_to_enumr�ra)rbrXrErdr�r��tokensr�rcrF�pairsr�rirhrgrhr@r@rA�process_unix�s@�
204  ���
205  
206  ��"�zConnections.process_unixcCs||jvrtd|d�dd�|jD��f��t�|_|dur(|�|�}|s'gSn|��}t�}|j|D]Q\}}}d|j|f}|tj	tj
207  fvrS|j|||||d�}	n	|j||||d�}	|	D]&\}
208  }}}}}
}|rtt
�|
209  |||||
�}nt
�|
210  |||||
|�}|�|�q^q4t|�S)Nz+invalid %r kind argument; choose between %sr�cSsg|]}t|��qSr@)�reprr�r@r@rAr��rz(Connections.retrieve.<locals>.<listcomp>z	%s/net/%s)rd)r:r�r�rr;rGrKrr4r5r7riror�pconn�sconnrrA)r<�kindr�rEr�Z
211  proto_namerXrcrhrrirfrgrhZ	bound_pid�connr@r@rA�retrieve�s@
212  �
213  �
214  �����zConnections.retrieverH)r=r>r?�__doc__r=rGrK�staticmethodr[rirorur@r@r@rAr(s
215  2'%r(r1cCs
216  t�|�S)z$Return system-wide open connections.)�_connectionsru)rsr@r@rA�net_connections�s
217  rycCs�tdt���}|��}Wd�n1swYi}|dd�D]F}|�d�}|dks4Jt|���|d|���}||dd�����}tt|�\}}}	}
218  }}}
}}}}}}}}}|||||	||
219  |f||<q#|S)zsReturn network I/O statistics for every network interface
220      installed on the system as a dict of raw tuples.
221      z
222  %s/net/devNr;rLrr)	rr�	readlines�rfindrpr�r��mapr�)r��lines�retdictr��colonr�r��
223  bytes_recv�packets_recv�errin�dropinZfifoinZframeinZcompressedinZmulticastin�
224  bytes_sent�packets_sent�errout�dropoutZfifooutZ
collisionsoutZ
225  carrieroutZ
compressedoutr@r@rA�net_io_counters�s<
226  �
227  �
228  �r�cCs�tjttjttjti}t���}i}|D]I}zt	�
229  |�}t	�|�}t�|�\}}Wnt
yF}z|jtjkr8�t|�WYd}~qd}~wwd�|�}	d|v}
230  t�|
231  |||||	�||<q|S)z)Get NIC stats (isup, duplex, speed, mtu).N�,�running)r�ZDUPLEX_FULLr
232  ZDUPLEX_HALFrZDUPLEX_UNKNOWNrr��keys�
233  cext_posix�
234  net_if_mtu�net_if_flags�net_if_duplex_speedr�r��ENODEVrr�r�	snicstats)�
235  duplex_map�namesr�r��mturl�duplex�speedr��output_flags�isupr@r@rA�net_if_statss.�
236  
237  
238  ��
239  
240  �r�FcCs�dd�}dd�}tj�dt��r|�}ntj�d�r|�}ntdt���i}|D]*}|\
241  }}}}	}
242  }}}
}}|s?t|�s?q*|	t9}	|
243  t9}
244  |||	|
245  |||
||f	||<q*|S)zcReturn disk I/O statistics for every disk installed on the
246      system as a dict of raw tuples.
247      cssB�tdt���}|��}Wd�n1swY|D]�}|��}t|�}|dkrJ|d}t|d�}tt|dd��\
248  }}}	}
249  }}}
}}}nG|dksR|dkrk|d}tt|dd��\}}}}	}
250  }}}
}}}n&|dkr�|d}tt|dd��\}}}
251  }d	}	}
}}}ntd
252  |��|||
253  |||	|
|||f
254  VqdS)N�%s/diskstats�r$r;r%��rjrz!not sure how to interpret line %r)rrrzr�r�r�r|r�)r�r}r�r��flenr��reads�reads_merged�rbytes�rtime�writes�
writes_merged�wbytes�wtimer�rfr@r@rA�read_procfsCs6�
255  �����z%disk_io_counters.<locals>.read_procfscss��t�d�D]^}t�tj�d|��D]Q\}}}d|vrqttj�|d���}|������}Wd�n1s8wYtj�	|�}t
256  t|dd��\
257  }}}	}
258  }}}
}}}||||	|
|
259  ||||f
260  VqqdS)N�
261  /sys/block�statr�)r�rB�walkrhr�rrr�r��basenamer|r�)�block�rootr��filesr�r�r�r�r�r�r�r�r�r�r�rfr@r@rA�
262  read_sysfsns"������z$disk_io_counters.<locals>.read_sysfsr�r�zC%s/diskstats nor /sys/block filesystem are available on this system)r�rhr^rrr��DISK_SECTOR_SIZE)�perdiskr�r��genr~r�r�r�r�r�r�r�r�r�r�rfr@r@rA�disk_io_counters?s0+
���
263  �r�c@s@eZdZdZddgZdd�Zdd�Zdd	�Zd
264  d�Zdd
�Z	dS)�RootFsDeviceFinderaEdisk_partitions() may return partitions with device == "/dev/root"
265      or "rootfs". This container class uses different strategies to try to
266      obtain the real device path. Resources:
267      https://bootlin.com/blog/find-root-device/
268      https://www.systutorials.com/how-to-find-the-disk-where-root-is-on-in-bash-on-linux/
269      �major�minorcCs(t�d�j}t�|�|_t�|�|_dS)Nr�)r�r��st_devr�r�)r<�devr@r@rAr=��zRootFsDeviceFinder.__init__cCs�tdt���X}|��dd�D]F}|��}t|�dkrq|d��r)t|d�nd}|d��r7t|d�nd}|d}||jkrV||jkrV|rVd|Wd�SqWd�dS1sbwYdS)Nz
%s/partitionsr;r%rrr$�/dev/%s)	rrrzr�r��isdigitr�r�r�)r<r�r�r�r�r�r�r@r@rA�ask_proc_partitions�s
270  ��"�z&RootFsDeviceFinder.ask_proc_partitionscCs�d|j|jf}t|��+}|D]}|�d�r.|���d�d}|r.d|Wd�SqWd�dS1s:wYdS)Nz/sys/dev/block/%s:%s/ueventzDEVNAME=r;r�)r�r�rr�r��
271  rpartition)r<rhr�r�r�r@r@rA�ask_sys_dev_block�s
272  
273  
274  ��"�z$RootFsDeviceFinder.ask_sys_dev_blockc	Cs�d|j|jf}t�d�}|D]E}zt|�}Wn	ty Yqw|�)|����}||krEtj	�
275  tj	�|��}d|Wd�SWd�n1sOwYqdS)Nz%s:%sz/sys/class/block/*/devr�)r�r�r�iglobrrrr�r�rhr��dirname)r<�needler�rbr��datar�r@r@rA�ask_sys_class_block�s$
276  �����z&RootFsDeviceFinder.ask_sys_class_blockc
277  Cs�d}|dur%z|��}Wnttfy$}z
278  t|�WYd}~nd}~ww|durHz|��}WnttfyG}z
279  t|�WYd}~nd}~ww|durkz|��}Wnttfyj}z
280  t|�WYd}~nd}~ww|durwtj�|�ry|SdSdSrH)	r�r�r�rr�r�r�rhr^)r<rhr�r@r@rA�find�s2�������zRootFsDeviceFinder.findN)
281  r=r>r?rv�	__slots__r=r�r�r�r�r@r@r@rAr��s
	r�c	Cs<t�}t�}td|��.}|D]#}|��}|�d�s"|�|���q|�d�d}|dkr2|�d�qWd�n1s=wY|dkrStj�	d�rStj�
282  d�}ntj�
283  d	|�}g}t�|�}|D]7}	|	\}
284  }}}|
285  d
286  krrd}
287  |
288  dvr}t
���p||
289  }
290  |s�|
291  dks�||vr�qdd}
}t�|
292  ||||
|�}|�|�qd|S)
z8Return mounted disk partitions as a list of namedtuples.z%s/filesystemsZnodev�	r�zfsNr�z	/etc/mtabz%s/self/mounts�nonerk)z	/dev/rootZrootfs)rrrr�r�rr�r�rh�isfile�realpathr��disk_partitionsr�r�r�	sdiskpartr�)r.Zfstypesr�r�r��fstypeZmounts_path�retlist�
293  partitions�	partition�device�
294  mountpoint�opts�maxfile�maxpath�ntupler@r@rAr��sB
295  
296  ���
297  �r�cCsDt�t�}t�d�}|�t�d��ttdd�|D���}t�d�}t�d�}|D]}|�	d|�}||vr:|�
298  |�q)|D]�}z|d}tt|��d	}t
j�t
j�|�d
299  �}t|���}	WntttfyjYq=wt|ddd
�}
300  t|ddd
�}t|ddd
���}|
301  dur�zt|
302  �d	}
303  Wnty�d}
304  Ynw|dur�zt|�d	}Wnty�d}Ynw||	�
305  |||
306  |f�q=|�s�t�d�}tt|��}|D]�}zt
j�|d�}tt|��d	}t
j�|d�}t|���}	Wntttf�y}
z
307  t|
�WYd}
~
q�d}
~
wwt�|d�}tdd�|D��}d}d}
308  |D]o}t
j�||d�}t|dd
���}|dk�rHtt
j�||d�dd
�}n|dk�rZtt
j�||d�dd
�}
309  |
310  du�rtzt|
311  �d	}
312  Wnt�ysd}
313  Ynw|du�r�z	t|�d	}W�q"t�y�d}Y�q"w�q"||	�
314  d||
315  |f�q�t|�S)a�Return hardware (CPU and others) temperatures as a dict
316      including hardware name, label, current, max and critical
317      temperatures.
318  
319      Implementation notes:
320      - /sys/class/hwmon looks like the most recent interface to
321        retrieve this info, and this implementation relies on it
322        only (old distros will probably use something else)
323      - lm-sensors on Ubuntu 16.04 relies on /sys/class/hwmon
324      - /sys/class/thermal/thermal_zone* is another one but it's more
325        difficult to parse
326      z/sys/class/hwmon/hwmon*/temp*_*z&/sys/class/hwmon/hwmon*/device/temp*_*cS�g|]	}|�d�d�qS�r�r�r�r�r@r@rAr�(r&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��_maxNrZ_crit�_labelrkz /sys/class/thermal/thermal_zone*�temp�typez/trip_point*cSs,g|]}d�tj�|��d�dd���qS)r�rr$)r�r�rhr�r�)r��pr@r@rAr�hs
327  ���_type�critical�_temp�high)�collectionsrrAr�extend�sortedrr�r��subr�r�rr�rhr�r�rr�r�r�r�r�dict)r��	basenamesZ
328  basenames2�replr�Zaltname�baserhr��	unit_namer�r��labelr�Z
329  trip_pathsZtrip_pointsZ
330  trip_pointZ	trip_typer@r@rA�sensors_temperaturess�
331  
332  �
333  
334  �	���
335  ���
336  �
337  �
338  �
339  
340  ��r�cCs�t�t�}t�d�}|st�d�}ttdd�|D���}|D]I}z
341  tt|d��}Wntt	fyB}z
342  t
343  |�WYd}~qd}~wwttj
�tj
�|�d����}t|dd	d
344  ���}||�t�||��qt|�S)a�Return hardware fans info (for CPU and other peripherals) as a
345      dict including hardware label and current speed.
346  
347      Implementation notes:
348      - /sys/class/hwmon looks like the most recent interface to
349        retrieve this info, and this implementation relies on it
350        only (old distros will probably use something else)
351      - lm-sensors on Ubuntu 16.04 relies on /sys/class/hwmon
352      z/sys/class/hwmon/hwmon*/fan*_*z%/sys/class/hwmon/hwmon*/device/fan*_*cSr�r�r�r�r@r@rAr��r&z sensors_fans.<locals>.<listcomp>r�Nr�r�rkr)r�rrArr�rr�rr�r�rrr�rhr�r�r�r�r�sfanr�)r�r�r�r�r�r�r�r@r@rA�sensors_fans�s"
353  
354  
355  
356  ��r�cs�t���fdd�}dd�t�t�D�}|sdStj�tt|�d�}||d|d�}||d	|d
357  �}||d|d�}||d
�}|dur_|dur_zd||}Wnty^d}Ynwtt	|ddd��}|dkrodSd}|tj�td�tj�td��}	|	dur�|	dk}nt	|ddd��
358  ���}
359  |
360  dkr�d}n|
361  dvr�d}|r�tj
}n4|dur�|dur�z
362  t||d�}Wn!ty�tj}Ynw|dur�t|d�}|dkr�tj}ntj}t�|||�S)aReturn battery information.
363      Implementation note: it appears /sys/class/power_supply/BAT0/
364      directory structure may vary and provide files with the same
365      meaning but under different names, see:
366      https://github.com/giampaolo/psutil/issues/966
367      c	sP|D]#}t|�d�}|�kr%zt|�WSty$|��YSwqdS)zvAttempt to read the content of multiple files which may
368          not exist. If none of them exist return None.
369          rN)rr�r�r�)rrhr���nullr@rA�
370  multi_bcat�s��z#sensors_battery.<locals>.multi_bcatcSs&g|]}|�d�sd|��vr|�qS)ZBATZbattery)r�r�r�r@r@rAr��s�z#sensors_battery.<locals>.<listcomp>Nrz/energy_nowz/charge_nowz
371  /power_nowz/current_nowz/energy_fullz/charge_fullz/time_to_empty_nowgY@r�z	/capacityr@rz
372  AC0/onlinez	AC/onlinerz/statusrkZdischargingF)�charging�fullTi�<)�objectr�rB�POWER_SUPPLY_PATHrhr�r��ZeroDivisionErrorr�rr�r�r�POWER_TIME_UNLIMITED�POWER_TIME_UNKNOWN�sbattery)r�Zbatsr�Z
373  energy_nowZ	power_nowZenergy_fullZ
time_to_emptyrV�
power_plugged�onlinerh�secsleftr@r�rA�sensors_battery�sn
�����
374  
375  ��rc
376  Cs\g}t��}|D]#}|\}}}}}}|sq|dvrd}t�||p!d|||�}	|�|	�q|S)z:Return currently connected users as a list of namedtuples.)z:0.0z:0�	localhostN)r��usersr�suserr�)
377  r��rawlist�itemrz�tty�hostname�tstamp�user_processr��ntr@r@rArsrcCsvdt�}t|��(}|D]}|�d�r*t|����d�}|a|Wd�Sqtd|��1s4wYdS)zAReturn the system boot time expressed in seconds since the epoch.r�sbtimerNzline 'btime' not found in %s)rrr�r�r�r��	BOOT_TIMEr_)rhr�r�r�r@r@rA�	boot_times
378  
379  
380  ���rcCsdd�t�tt���D�S)z7Returns a list of PIDs currently running on the system.cSsg|]
381  }|��rt|��qSr@)r�r�r�r@r@rAr�-szpids.<locals>.<listcomp>)r�rBr"rr@r@r@rArI+�rIc	Cs�t�|�sdSz=dt�|f}t|��'}|D]}|�d�r3t|��d�}||kWd�WSqtd|��1s=wYWdSttfyT|t	�vYSw)zcCheck for the existence of a unix PID. Linux TIDs are not
382      supported (always return False).
383      F�%s/%s/statussTgid:rNz'Tgid' line not found in %s)
384  r�
385  pid_existsrrr�r�r�r��EnvironmentErrorrI)r�rhr�r�Ztgidr@r@rAr0s 
386  
387  
388  
389  
390  ���rc
391  Cs�i}t�}t�D]E}ztd||f��}|��}Wd�n1s"wYWnttfy3Yqw|�d�}||dd���}t|d�}|||<q|S)zsObtain a {pid: ppid, ...} dict for all running processes in
392      one shot. Used to speed up Process.children().
393394  %s/%s/statN�)r;r)	rrIrrrr!r{r�r�)r�r�r�r�r��rpar�dset�ppidr@r@rA�ppid_mapPs 
395  
396  ���
397  
398  rcst����fdd��}|S)zlDecorator which translates bare OSError and IOError exceptions
399      into NoSuchProcess and AccessDenied.
400      cs�z�|g|�Ri|��WStyt|j|j��ty't|j|j��tyAtj�	d|j
401  |jf�s@t|j|j���w)N�%s/%s)r r
r��_namer!rrr�rhr^r;)r<�args�kwargs��funr@rA�wrapperjs�z wrap_exceptions.<locals>.wrapper)�	functools�wraps)rrr@rrA�wrap_exceptionsfs
r c@s~eZdZdZgd�Zdd�Zdd�Zeedd���Z	eed	d
402  ���Z
403  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(��Zes�er�ed)d*��Zee �!d+�e �!d,�e �!d-�fd.d/��Z"d0d1�Z#neZ#er�ed2d3��Z$ed4d5��Z%ee �!d6�fd7d8��Z&ee �!d9�fd:d;��Z'ed<d=��Z(ed>d?��Z)ed@dA��Z*e+r�edBdC��Z,e �!dD�fdEdF�Z-edGdH��Z.e/r�edIdJ��Z0edKdL��Z1e2d"u�red`dMdN��Z3edOdP��Z4edQdR��Z5edadTdU��Z6edVdW��Z7edXdY��Z8ee �!dZ�fd[d\��Z9ee �!d]�fd^d_��Z:d"S)b�ProcesszLinux process implementation.)r�r�_ppidr;�_cachecCs||_d|_d|_t�|_dSrH)r�rr"rr;)r<r�r@r@rAr=�szProcess.__init__cCst�d|j|jf�dS)z+Raise NSP if the process disappeared on us.rN)r�r�r;r��r<r@r@rA�
_assert_alive�szProcess._assert_alivecCs�td|j|jf�}|�d�}||�d�d|�}||dd���}i}||d<|d|d	<|d|d
404  <|d|d<|d
|d<|d|d<|d|d<|d|d<|d|d<|d|d<|d|d<|S)aYParse /proc/{pid}/stat file and return a dict with various
405          process info.
406          Using "man proc" as a reference: where "man proc" refers to
407          position N always subtract 3 (e.g ppid position 4 in
408          'man proc' == position 1 in here).
409          The return value is cached in case oneshot() ctx manager is
410          in use.
411          rr�(rr;Nr�rrhrr%�ttynr��utime��stime�
�children_utimer��children_stime��create_time�$�cpu_num�'�blkio_ticks)rr;r�r{r�r�)r<r�rr�r�r�r@r@rA�_parse_stat_file�s"
412  zProcess._parse_stat_filecCs@td|j|jf��}|��Wd�S1swYdS)z�Read /proc/{pid}/stat file and return its content.
413          The return value is cached in case oneshot() ctx manager is
414          in use.
415          rN)rr;r�r�r<r�r@r@rA�_read_status_file�s$�zProcess._read_status_filecCsDtd|j|jf��}|����Wd�S1swYdS)Nz%s/%s/smaps)rr;r�rr�r6r@r@rA�_read_smaps_file�s
416  $�zProcess._read_smaps_filecC�(|j�|�|j�|�|j�|�dSrH)r5�cache_activater7r8r$r@r@rA�
oneshot_enter�r�zProcess.oneshot_entercCr9rH)r5�cache_deactivater7r8r$r@r@rA�oneshot_exit�r�zProcess.oneshot_exitcCs|��d}trt|�}|S)Nr�)r5rr)r<r�r@r@rAr��szProcess.namec	Cs�ztd|j|jf�WSttfy8tj�d|j|jf�r#YdSt|j�s/t	|j|j
417  ��t|j|j
418  |j��t
yEt|j|j
419  ��w)Nz	%s/%s/exerrk)r�r;r�rr!r�rh�lexistsrrrrr"r r
r$r@r@rA�exe�s
420  �zProcess.execCs�td|j|jf��}|��}Wd�n1swY|s"gS|�d�r)dnd}|�|�r6|dd�}|�|�}|dkrNt|�dkrNd|vrN|�d�}|S)Nz
%s/%s/cmdlinerrwr@r)rr;r�rr�r�r�)r<r�r��sep�cmdliner@r@rArA�s
421  �
422  
423  
424  zProcess.cmdlinecCsJtd|j|jf��}|��}Wd�t|�S1swYt|�S)Nz
%s/%s/environ)rr;r�rr)r<r�r�r@r@rA�environ�s
425  
426  ��zProcess.environcCs8t|��d�}t��}z||WStyYdSw)Nr')r�r5r�get_terminal_mapr�)r<�tty_nrr:r@r@rA�terminals
427  �zProcess.terminalz/proc/%s/ioc
428  Cs�d|j|jf}i}t|��,}|D]!}|��}|r2z	|�d�\}}Wn	ty+Yqwt|�||<qWd�n1s=wY|sJtd|��zt|d|d|d|d|d|d	�WSt	yw}ztd
429  |d||f��d}~ww)Nz%s/%s/ios: z%s file was emptyssyscrssyscws
430  read_bytesswrite_bytessrcharswcharz1%r field was not found in %s; found fields are %rr)
431  r;r�rr�r�r�r�r_rxr�)r<�fnamer�r�r�r�r
r�r@r@rA�io_counterss@
432  ��������zProcess.io_counterscCsh|��}t|d�t}t|d�t}t|d�t}t|d�t}t|d�t}t|||||�S)Nr)r+r-r.r4)r5r�r�ry)r<r�r)r+r-r.r~r@r@rAr�*szProcess.cpu_timescC�t|��d�S)zWhat CPU the process is on.r2�r�r5r$r@r@rAr24szProcess.cpu_numNcCst�|j||j�SrH)r�wait_pidr�r)r<�timeoutr@r@rA�wait9szProcess.waitcCs&t|��d�}tpt�}|t|S)Nr0)r�r5rrr�)r<�ctime�btr@r@rAr0=s
433  zProcess.create_timec	Csttd|j|jf��}dd�|����dd�D�\}}}}}}}Wd�n1s+wYt|||||||�S)Nz%s/%s/statmcSsg|]}t|�t�qSr@)r�r�r�r@r@rAr�Wr�z'Process.memory_info.<locals>.<listcomp>rj)rr;r�r�r�rm)	r<r��vmsrsr]�text�libr��dirtyr@r@rA�memory_infoHs
434  
��zProcess.memory_infocCs�d}}}zRtd�|j|j���>}|D]3}|�d�r(|t|��d�d7}q|�d�r8t|��d�d}q|�d�rGt|��d�d}qWd�n1sRwYWntytt|j�skt	|j|j
435  ��t|j|j
436  |j��w|||fS)Nrz{}/{}/smaps_rollupsPrivate_rr��Pss:�Swap:)
r�formatr;r�r�r�r�r!rrrrr")r<rorprqr�r�r@r@rA�_parse_smaps_rollup\s.�
437  
438  
439  ����
440  
441  �
442  zProcess._parse_smaps_rollups\nPrivate.*:\s+(\d+)s\nPss\:\s+(\d+)s\nSwap\:\s+(\d+)cCsZ|��}ttt|�|���d}ttt|�|���d}ttt|�|���d}|||fS)Nr�)r8rr|r��findall)r<Z_private_reZ_pss_reZ_swap_reZ
443  smaps_datarorprqr@r@rA�_parse_smapsts
444  
445  zProcess._parse_smapscCs<tr
446  |��\}}}n|��\}}}|��}t||||f�SrH)�HAS_PROC_SMAPS_ROLLUPrWrYrSrn)r<rorprq�	basic_memr@r@rA�memory_full_info�s
447  zProcess.memory_full_infocCsPdd�}|��}|sgS|�d�}g}|�d�}|g}|||�D]�\}}|�dd�}z
448  |\}	}
449  }}}
}WntyH|dg\}	}
450  }}}
}Ynw|sNd}ntrTt|�}|��}|�d	�rgt|�sg|dd
451  �}|�	t|	�t|
452  �||�
453  dd�|�
454  dd�|�
455  d
d�|�
456  dd�|�
457  dd�|�
458  dd�|�
459  dd�|�
460  dd�|�
461  dd�|�
462  dd�f
�q |S)aPReturn process's mapped memory regions as a list of named
463              tuples. Fields are explained in 'man proc'; here is an updated
464              (Apr 2012) version: http://goo.gl/fmebo
465  
466              /proc/{PID}/smaps does not exist on kernels < 2.6.14 or if
467              CONFIG_MMU kernel configuration option is not enabled.
468              c	ss��i}|D]@}|�dd�}|d�d�s!|��|fV|�|�qzt|d�d||d<WqtyE|d�d�r?Yqtd|��w|��|fVdS)N�rrrr�sVmFlags:z#don't know how to interpret line %r)r�r��popr�r�r�r�)r}�
current_blockr�r�r�r@r@rA�
469  get_blocks�s"���z'Process.memory_maps.<locals>.get_blocks�
470  rNr]rkz[anon]r�r�sRss:sSize:rTs
Shared_Clean:s
Shared_Dirty:sPrivate_Clean:sPrivate_Dirty:sReferenced:s
471  Anonymous:rU)r8r�r^r�rrr�r�rr�r�)r<r`r�r}r�
472  first_liner_�headerZhfieldsrW�perms�offsetr�rFrhr@r@rA�memory_maps�sN	
473  
474  ��
475  �
476  
477  
478  
479  
480  
481  
482  
483  
484  
485  �
zProcess.memory_mapsc	CsTztd|j|jf�WSttfy)t|j�s t|j|j��t|j|j|j	��w)Nz	%s/%s/cwd)
486  r�r;r�rr!rrrrr"r$r@r@rA�cwd�s
487  �zProcess.cwdsctxt_switches:\t(\d+)cCsF|��}|�|�}|std|j|jf��t�t|d�t|d��S)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)r7rXrr;r�r�pctxswr�)r<Z	_ctxsw_rer��ctxswr@r@rA�num_ctx_switches�s
488  ���zProcess.num_ctx_switchessThreads:\t(\d+)cCs|��}t|�|�d�S�Nr)r7r�rX)r<Z_num_threads_rer�r@r@rA�num_threads�szProcess.num_threadsc
489  Cst�d|j|jf�}|��g}d}|D]c}d|j|j|f}zt|��}|����}Wd�n1s6wYWn
tt	fyId}Yqw||�
490  d�dd�}|�d�}t|d�t
}	t|d	�t
}
491  t�t|�|	|
492  �}|�|�q|r|��|S)
493  Nz
494  %s/%s/taskFz%s/%s/task/%s/statTrr;r�r(r*)r�rBr;r�rrrr�rr!r�r�r�r�r�pthreadr�r�r%)r<Z
495  thread_idsr��
496  hit_enoent�	thread_idrFr��str�r)r+r�r@r@rA�threadss4
497  �
498  ���
499  zProcess.threadscC�t�|j�SrH)r��getpriorityr�r$r@r@rA�nice_get szProcess.nice_getcCst�|j|�SrH)r��setpriorityr�)r<r
r@r@rA�nice_set)szProcess.nice_setcCrrrH)r�r7r�r$r@r@rA�cpu_affinity_get0szProcess.cpu_affinity_getsCpus_allowed_list:\t(\d+)-(\d+)cCsR|��}|�|�}|r ttt|dd�t|dd�d��Stttt����S)Nrr)r7rXrA�ranger�r�r�)r<�_rer�r�r@r@rA�_get_eligible_cpus4s
500  
501  *zProcess._get_eligible_cpusc
502  Cs�z
503  t�|j|�WdSttfyN}z6t|t�s|jtjkrI|��}t	t
504  tt����}|D]}||vr<td||f��||vrHtd||f��q.�d}~ww)Nz(invalid CPU number %r; choose between %sz0CPU number %r is not eligible; choose between %s)
r��proc_cpu_affinity_setr�r�r�r�r�rCrz�tuplerxr�r�)r<r�r�Z
eligible_cpusZall_cpus�cpur@r@rA�cpu_affinity_set>s.�������zProcess.cpu_affinity_setcCs,t�|j�\}}tdurt|�}t�||�SrH)r�r6r��enumr<r�pionice�r<�ioclassr
r@r@rA�
505  ionice_getTszProcess.ionice_getcCsP|durd}|r|ttfvrtd|��|dks|dkr td��t�|j||�S)Nrz%r ioclass accepts no valuerjzvalue not in 0-7 range)r*r'r�r�Zproc_ioprio_setr�r�r@r@rA�
506  ionice_set[szProcess.ionice_setc
507  Cs�|jdkr	td��z#|durt|j|�WSt|�dkr#tdt|���t|j||�WdStyM}z|jtjkrHt|j�rHt	|j|j
508  |j���d}~ww)Nrz)can't use prlimit() against PID 0 processr;z4second argument must be a (soft, hard) tuple, got %s)r�r�r�r�rpr�r�ZENOSYSrrrr")r<r�r�r�r@r@rA�rlimitgs$
509  ����zProcess.rlimitcCs$|��d}tr|��}t�|d�S)Nrh�?)r5rr�
PROC_STATUSESr�)r<�letterr@r@rArh�szProcess.statusc
Cs�g}t�d|j|jf�}d}|D]�}d|j|j|f}zt|�}Wn5ttfy/d}YqtyW}z|jtj	krBWYd}~q|jtj
510  krRt|�WYd}~q�d}~ww|�d�r�t
|�r�d|j|j|f}z+t|��}t|����d�}	t|����dd�}
511  Wd�n1s�wYWn
ttfy�d}Yqwt|
512  �}t|t|�t|	�||
513  �}|�|�q|r�|��|S)	Nr>Fr?Tr�z%s/%s/fdinfo/%srr�)r�rBr;r�r�rr!r�r�rCrDrr�rrr�r�r�r�rgr�r%)
r<r�r�rnrirbrhr�r��posrlrkr�r@r@rA�
514  open_files�sR��
515  �
516  ����
517  �zProcess.open_filesr1cCst�||j�}|��|SrH)rxrur�r%)r<rsr�r@r@rA�connections�szProcess.connectionscCstt�d|j|jf��S)Nr>)r�r�rBr;r�r$r@r@rA�num_fds�r
zProcess.num_fdscCrH)NrrIr$r@r@rAr�szProcess.ppidsUid:\t(\d+)\t(\d+)\t(\d+)cC�6|��}|�|�d\}}}t�t|�t|�t|��Srk)r7rXr�puidsr�)r<Z_uids_rer��real�	effective�savedr@r@rA�uids��zProcess.uidssGid:\t(\d+)\t(\d+)\t(\d+)cCr�rk)r7rXr�pgidsr�)r<Z_gids_rer�r�r�r�r@r@rA�gids�r�zProcess.gidsrH�r1);r=r>r?rvr�r=r%r rr5r7r8r;r=r�r?rArBrEr�rhr^�getpidrGr�r2rLr0rSrZ�HAS_PROC_SMAPSrWr�r�rYr\rfrgrjrlrqrtrv�HAS_CPU_AFFINITYrwrzr~�HAS_PROC_IO_PRIORITYr�r�r�r�rhr�r�r�rr�r�r@r@r@rAr!{s� 
518  
519  
520  
521  	
522  
523  	
524  
525  
526  
527  
528  �
529  	
530  C
531  
532  �

533  
534  
535  
536  
537  �
538  
539  
540  
541  
542  	
543  
544  /
545  
546  r!rHr�)F)�rv�
547  __future__rrRr�r�rrr�r�r4rT�sys�	tracebackr�rrrkrrrr�r	r�r
548  rrr
rrrrrrrrrrrrrrrr�_compatrrr r!r"r#�version_infor�__extra__all__r�rhr^r�r�rZ�hasattrr�r�r�r��getpagesizer�r�	byteorderrPr��	AF_PACKETr:�IntEnumr�r9r'r(r)r*r<�globalsrJ�__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_PARKEDr�r+r,r-r.r/r0r1r2r3r4r5r`rSr_rgrmr�rnrrr�rvrxryr�r�r�r��	Exception�	print_excr�r��resource�ImportErrorr��CDLLr�r��dirr�r�r�r�r�r�rrrr%�net_if_addrsr'r(rxryr�r��
549  disk_usager�r�r�r�r�rrrrIrrr r�r!r@r@r@rA�<module>sj
550  
551  
552  
553  
554  
555  �
556  �����
557  ���
558  

559  �
560  ��
561  �	4z:*
562  �
563  !o
564  %
565  _
566  J-qa