mf@ dZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd 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#krddl2Z2ndZ2gd$Z3d%Z4ej56d&ej7zZ8e9ed'Z:e9ed(Z;e<Z=ej>d)Z?ej@ZAdaBe0rd*nd+ZCe jDd,kZEd-ZFe2e jGZHn(e2jId.d/eJe jGiZKeKjHZHe2 dZLdZMd0ZNd1ZOn5Gd2d3e2jIZPeQRePjSejTejUejVejWejXejYejZejZej[ej\ej]ej^d4 Z_ej`ejaejbejcejdejeejfejgejhejiejjd5 Zked6gd7Zled8gd9Zmed:gd;Znedeojpd?zZqed@gdAZredBdCdDserjpzZtedEgdFZuedGgdHZvdIZwdJZxdKZyedLZze=dMfdNZ{ ezdOn1#e|$r)e j}edPdQdRdRdRa~YnwxYwdZ ddSlmZn1#e$r)ddlZejddMTZe9edUrd|dVZYnwxYwe(e3dWeeDdXZdYZdZZd[Zd\Zd]Zd^Zd_Zej56d`sej56dardbZn!ej56dcrddZndeZejZGdfdge|ZGdhdiZeZd}dkZdlZdmZejZd~doZd~dpZdqZdrZdsZdtZduZdvZdwZdxZdyZGdzd{e<ZdS)zLinux platform implementation.)divisionN) defaultdict) namedtuple)_common)_psposix) _psutil_linux) _psutil_posix) AccessDenied)debug)decode)get_procfs_path) isfile_strict)memoize)memoize_when_activated)NIC_DUPLEX_FULL)NIC_DUPLEX_HALF)NIC_DUPLEX_UNKNOWN) NoSuchProcess) open_binary) open_text)parse_environ_block)path_exists_strict) supports_ipv6) usage_percent) ZombieProcess)b) basestring)FileNotFoundError)PermissionError)ProcessLookupError)PY3)) PROCFS_PATHIOPRIO_CLASS_NONEIOPRIO_CLASS_RTIOPRIO_CLASS_BEIOPRIO_CLASS_IDLECONN_ESTABLISHED CONN_SYN_SENT CONN_SYN_RECVCONN_FIN_WAIT1CONN_FIN_WAIT2CONN_TIME_WAIT CONN_CLOSECONN_CLOSE_WAIT CONN_LAST_ACK CONN_LISTEN CONN_CLOSINGz/sys/class/power_supplyz/proc/%s/smapsproc_ioprio_getproc_cpu_affinity_get SC_CLK_TCKi littlei AddressFamilyAF_LINKr#ceZdZdZdZdZdZdS) IOPriorityrrr<r#N)__name__ __module__ __qualname__r&r'r(r)F/opt/imunify360/venv/lib64/python3.11/site-packages/psutil/_pslinux.pyr>r>ws&rCr>) RSDTtZXxKWIP) 0102030405060708090A0Bsvmem) total availablepercentusedfreeactiveinactivebufferscachedsharedslabsdiskio) read_count write_count read_bytes write_bytes read_time write_timeread_merged_countwrite_merged_count busy_time popenfile)pathfdpositionmodeflagspmemz"rss vms shared text lib data dirtypfullmem)usspssswap pmmap_grouped) rsrsssizer{ shared_clean shared_dirty private_clean private_dirty referenced anonymousr| pmmap_extz addr perms  pio)rirjrkrl read_chars write_chars pcputimes)usersystem children_userchildren_systemiowaitct|ts J|tj|}|dd}|drt |s |dd}|S)zWrapper around os.readlink().r (deleted)N) isinstancerosreadlinksplitendswithr)rss rDrrs dJ ' '---- ' ;t  D ::f  a D }}\""+=d+C+CDSDz KrCc(tjdtjdtjdi}||tjtjztjzz}|tjzr|ddd}|dd}|S)zZConvert file's open() flags into a readable string. Used by Process.open_files(). rwzw+arzr+)rO_RDONLYO_WRONLYO_RDWRO_APPENDreplace)rw modes_maprvs rDfile_flags_to_moderswc2;RYEI UbkBK7")CD ED r{)||Ca(( <<d # #D KrCc|dd}d}|rd|z}nd|z}tj|tjS)zReturn 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)rraccessF_OK)nameincluding_virtualrss rDis_storage_devicersO <<S ! !D-%%, 9T27 # ##rCctd|z5}|dd}dddn #1swxYwYgd}t|}|dkr|d|dkr|d|d kr|d t d |adS) zSet 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)rniceridlerirqsoftirqsteal guest guest_nice scputimes)rreadlinerlenappendrr) procfs_pathfvaluesfieldsvlens rDset_scputimes_ntuplers Y, - -*##%%abb)*************** K K KF v;;D qyy g qyy g rzz l###;//IIIs/AAATc  |rt|nt|5}|cdddS#1swxYwYdS#tt f$r|t ur|cYSwxYw)zReturn 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)rrreadstripIOErrorOSError_DEFAULT)fnamefallbackbinaryrs rDcatrs #) ?[   y/?/? $16688>>## $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ W  8 # #OOO  s4 A"&A A"AA"AA""BB/procrzuser system idle)prlimit) use_errnorcGddtj}|}|0t||dtj|}ne|}|d|_|d|_t||tj|tj|}|dkr5tj}t|tj ||j|jfS)Nc2eZdZdejfdejfgZdS)prlimit..StructRlimitrlim_currlim_maxN)r?r@rActypes c_longlong_fields_rBrCrD StructRlimitrJs+'):;'):;=rCrrr) r Structurelibcrbyrefrr get_errnorrstrerror)pid resource_limitsrcurrentretnewerrnos rDrrIs = = = = =v/ = = =#lnnG~ll3 4g9N9NOO#lnn%ay %ay llFL$5$5v|G7L7LNNaxx(**eR[%7%7888$g&67 7rCcdg|]-}|d|+|.S)RLIM) startswithisupper.0rLs rD rbs6FFFqf!5!5F!))++FFFFrCc|d}||ddz} |d}|d}|d}n#t$r|cYSwxYw tdtz}n#t$r|cYSwxYwd}|5|D]U}|}|dr*|t|d z }V d d d n #1swxYwY|tz}||z } ||z} | t| d z |z} | | z } | |t|d z |z z } t| S) aFallback 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@) getKeyErrorrrrrrintrPAGESIZEmin) memsrarlru_active_filelru_inactive_fileslab_reclaimabler watermark_lowlineavail pagecaches rDcalculate_avail_vmemrjs.  Ddhhz1---H/0 !34 01   (9(99 : : M 66 6 6D::<*** wd7FFD B BBs;A++A/2A/B!B43B48C!C>=C>D E DE !EE EE E  E!E:9E:>F GF-,G-!GGGGGG$$ G32G3 HH21H2cDi}tdtz5}|D]7}|}t|ddz||d<8 dddn #1swxYwY |d}|d}n5#t$r(t j\}}}}}}}||z}||z}YnwxYw||z }t||d} td tz}|5dx} } |D]}|d r/t|d dd zdz} nC|d r.t|d dd zdz} | | n!d} tj | tdx} } dddn #1swxYwYnG#t$r:} dt| z} tj | tdx} } Yd} ~ nd} ~ wwxYwtj|||| | | S)zReturn swap memory metrics.rrrrNs SwapTotal:s SwapFree:rz %s/vmstatspswpin r$spswpoutzK'sin' and 'sout' swap memory stats couldn't be determined and were set to 0zP'sin' and 'sout' swap memory stats couldn't be determined and were set to 0 (%s))rrrrrcext linux_sysinforrrr r rstrrsswap)rrrrr]ra_unit_multiplierr`r_sinsoutr errs rD swap_memoryrs D \O$5$55 6 64! 4 4DZZ\\F!&)nnt3DOO 4444444444444444 ]#L!    373E3G3G01aE4    4D?t'7E 8 c>222d%                57:3xx@ c>***dddddd 4 =dGS$ ? ??sN;A))A-0A-5B/B87B8G3B7F66F:=F: H 0HHcNt}t|td|z5}|}dddn #1swxYwY|dt t jdz}d|D}t |S)zReturn 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. rNrc<g|]}t|tz SrBfloat CLOCK_TICKSrs rDrzcpu_times..^s# 5 5 5eAhh$ 5 5 5rC)rrrrrrr_fields)rrrrs rD cpu_timesr Rs"##K%%% Y, - -&##%%&&&&&&&&&&&&&&& Ac)+,,q00 1F 5 5f 5 5 5F f s'A##A'*A'ct}t|g}td|z5}||D]y}|drb|}|dt tjdz}d|D}t|}| |z|cdddS#1swxYwYdS)zfReturn a list of namedtuple representing the CPU times for every CPU available on the system. rscpurc<g|]}t|tz SrBrrs rDrz!per_cpu_times..ps#AAAQ%(([0AAArCN) rrrrrrrrrr)rcpusrrrrentrys rD per_cpu_timesr%bs%"##K%%% D Y, - -   # #Dv&& ##i&7"8"81"< <=AA&AAA!6* E"""                  sBCCCcN tjdS#t$rd}tdt z5}|D].}|dr|dz }/ dddn #1swxYwY|dkrtjd}tdt z5}|D]7}| d d}| |r|dz }8 dddn #1swxYwY|dkrYdS|cYSwxYw) z0Return the number of logical CPUs in the system.SC_NPROCESSORS_ONLNr %s/cpuinfos processorrNzcpu\drr) rsysconf ValueErrorrrlowerrrecompilerrmatch)numrrsearchs rDcpu_count_logicalr1vsz/000  (9(99 : : a  ::<<**<881HC                 !88Z))F9'8'8899 !Q!!D::c??1-D||D))!q! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !8844 -s]+D$2B4 D$B D$B ;D$;D ? D$ D D$D  D$D$#D$cPt}d}d}tj|ptj|D]b}t|5}||dddn #1swxYwYct |}|dkr|Si}i}tdtz5}|D]}|}|s& |d||d<n#t$rYnwxYwi}P| dr+| d d \} } t| || < dddn #1swxYwYt|}|pdS) z2Return the number of physical 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)r4r3s :r)setglobraddrrrrr+rrrrsumr) lsp1p2rsrresultmapping current_inforkeyvalues rDcpu_count_physicalrAs0 B EB JB " .2%%    %! FF16688>>## $ $ $ % % % % % % % % % % % % % % % WWF {{ GL \O$5$55 6 63! 3 3D::<<%%''D 3$\2L899D! ??#ABB3!%FA!6!6JC(+E L% 3333333333333333"!! " "F >TsI :BB B -E8DE8 D$!E8#D$$AE88E<?E<c2tdtz5}d}d}d}|D]}|dr(t|d}ny|dr(t|d}n<|dr't|d}|||ndddn #1swxYwYd}t j||||S)z*Return various CPU stats as a named tuple.rNsctxtrsintrssoftirqr)rrrrrr scpustats)r ctx_switches interruptssoft_interruptsrsyscallss rD cpu_statsrHsR Y!2!22 3 3 q    Dw'' 7"4::<<?33 )) 7 a11 ,, 7"%djjll1o"6"6'O,G".               H  j/8 = ==sC C55C9<C9z'/sys/devices/system/cpu/cpufreq/policy0z$/sys/devices/system/cpu/cpu0/cpufreqc 6d}g}ttD]}||}|stjj}t ||dd}|,t ||dd}|t dt|dz }tt ||ddz }tt ||d dz }|tj ||||S) zReturn frequency metrics for all CPUs. Contrarily to other OSes, Linux updates these values in real-time. cfd|zd|zfD]%}tj|r|cS&dS)Nz(/sys/devices/system/cpu/cpufreq/policy%sz%/sys/devices/system/cpu/cpu%s/cpufreq)rrsexists)r/ps rDget_pathzcpu_freq..get_pathsR@3F=CE  7>>!$$HHH  rCscaling_cur_freqNrcpuinfo_cur_freqz!can't find current frequency fileiscaling_max_freqscaling_min_freq) ranger1rrsrrNotImplementedErrorrrrscpufreq)rMrnrspjoincurrmax_min_s rDcpu_freqr[s=     (**++ ; ;A8A;;D GLEuuT#566FFFD|55'9::TJJJ<-;===t99t#Ds55'9::;;< ("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 :rBasciiNr8z>4Iz<4I)rrr"encoderorp LITTLE_ENDIAN inet_ntopbase64 b16decoderrstructpackunpackr*rr`raddr)rfamilyipports rDdecode_addresszConnections.decode_address]s"::c??D4}} 2  $7##B V^ # # D%ff.>r.B.B44R4.HII%ff.>r.B.BCC!"%%B  G) EEFM%,D,DEEEGGBB ) EEFM%,D,DEEEGGB   $//   |B%%%s B E!E<Nc # K|dr!tj|sdSt |t 5}|t|dD]\}} |dd\ }} } } }}}}}} n&#t$rtd|d|d|wxYw| |vr|| d \} }nd \} }||| krx|tj krt| } n tj} t | |} t | |} n#t$$rYwxYw|||| | | | fV ddddS#1swxYwYdS) z.Parse /proc/net/tcp* and /proc/net/udp* files.6N bufferingrrerror while parsing ; malformed line rrNr8)rrrsrKrBIGFILE_BUFFERINGr enumeraterr* RuntimeErrorrorq TCP_STATUSESr CONN_NONErbrr`)filertype_r filter_pidrlinenorrladdrraddrstatusrrrts rD process_inetzConnections.process_inets6 ==   bgnnT&:&:  F t'8 9 9 9 IQ JJLLL )!Q I I 1 SbS)BAueVQ1aEE!111&, DD&&&$$01111F??%UmA.GC&GC)jC.?.? 222!-f!5!(!2! + : :5& I I + : :5& I I0!!! !vueUFCHHHHH= I I I I I I I I I I I I I I I I I I IsO*E8:'B"!E8"#CAE86E E8 EE8EE88E<?E<c #0Kt|t5}||D]}|} |dd\}}}}}}} n)#t$rd|vrY:t d|d|wxYw| |vr || } ndg} | D]f\} } ||| krt |d kr |d } nd } tjt|}d }tj }| ||| ||| fVg ddddS#1swxYwYdS) zParse /proc/net/unix files.rrrrrrNrr8) rrrrr*rrrsocktype_to_enumrr)rrrrrrtokensrrrpairsrrtrsrrs rD process_unixzConnections.process_unixst'8 9 9 9! LQ JJLLL L L)281+/Aq!Qq%%!)))$ &, DD$$())) )F??#5MEE'LE$LLGC!-*2C2C v;;!++#)":DD#%D ' 8U D D!#!(!2!65$vsKKKKKL# L! L! L! L! L! L! L! L! L! L! L! L! L! L! L! L! L! L! Ls6-D AD B(D *BA=D  DDc ||jvr7td|ddd|jDt|_|||}|sgSn|}t}|j|D]\}}}|jd|}|tj tj fvr| |||||} n| ||||} | D]U\} }}} } } }|rtj| ||| | | }ntj| ||| | | |}||Vt#|S)Nzinvalid z kind argument; choose between rc,g|]}t|SrB)reprrs rDrz(Connections.retrieve..s0L0L0LQa0L0L0LrCz/net/)r)rur*rrrvrrr5rorprrrrrpconnsconnr7r|)rwkindrrr proto_namerrrsr9rtrrr bound_pidconns rDretrievezConnections.retrieves ty * $dii0L0L$)0L0L0L&M&M&MOPP P+-- ?))#..F   ((**Fee)-4   %J"&"3"3"3ZZ@D&.&/:::&&&%C'AA&&&&S'::FH  BFE5%<"=VUE5)/11DD#=VUE5)/<.read_procfsLs"~(9(99 : : "aKKMME " " " " " " " " " " " " " " " ; ;DZZ\\Fv;;DrzzayF1I69#vad|6L6L4vufmE1itrzzay69#vad|6L6L4 feV]E1iay03C0D0D-vvvKLLLL L}yy !Dt!KLLLu ; ; ; ; ;+ ; ;sAA Ac 3\KtjdD]}tjtjd|D]\}}}d|vr t tj|d5}|}dddn #1swxYwYtj |}tt|dd\ }}} } } } } }}}||| | | | ||| |f VސdS)N /sys/blockstatr) rr}walkrsrrrrrbasenamerr)blockrootrfilesrrrrrrrrrrrrqs rD read_sysfsz$disk_io_counters..read_sysfsws}Z -- F FE"$'"',,|U*K*K"L"L F Fa&&rw||D&99::6aVVXX^^--3355F666666666666666w''--36sF3B3K3H3H1 feV]E1iUFFFElM9FFFFF F F Fs9C  C C rrzC%s/diskstats nor /sys/block filesystem are available on this system)rrsrKrrTrDISK_SECTOR_SIZE)perdiskrrgenrr$rrrrrrrrrrqs rDdisk_io_countersrHs-);););V F F F w~~n'8'8899*kmm  % %*jll! &(( )** *GAA(- &ufffeUL 9 066  """"u%}iA  NrCc Lt}t}td|z5}|D]}|}|ds(||S|dd}|dkr|d dddn #1swxYwY|dkr?tj dr tj d}n"tj d |z}g}tj |}|D]P} | \} } }} | d krd } |s | d ks||vrdx} }tj| | || | |}||Q|S) z8Return mounted disk partitions as a list of namedtuples.z%s/filesystemsnodev rzfsNrz /etc/mtabz%s/self/mountsnoner)r5rrrrr7rrrsisfilerealpathrdisk_partitionsr sdiskpartr)rifstypesrrrfstype mounts_pathretlist partitions partitiondevice mountpointoptsmaxfilemaxpathntuples rDrrseeG!##K #k1 2 2 'a ' 'D::<.&???AGGCLLO???rCz5/sys/devices/platform/coretemp.*/hwmon/hwmon*/temp*_*z'/sys/devices/platform/coretemp.*/hwmon/z/sys/class/hwmon/_inputg@@rFr_maxNrO_crit_labelrrrz /sys/class/thermal/thermal_zone*temptypez ignoring z for file z /trip_point*cg|]O}dtj|dddPS)rrr#)rrrsrr)rrLs rDrz(sensors_temperatures..%sfJJJ9: #xx  ##))#..qs3 5 5JJJrC_typecritical_temphigh) collectionsrr|r6extendsortedr5r,r-subrrrrrsrdirnamerrr*r dict)r basenames basenames2replraltnamebasersr unit_namer/r-labelr trip_paths trip_points trip_point trip_types rDsensors_temperaturesrAs  !$ ' 'C ;<>DD///II*-    H 4&=4000tg~555D8Ob???   T{{V+        ??V3     IugtX>???? (AI@AA 3y>>** $ A$ AD w||D&11D **V3w||D&11U333 Wj1   333=>>> 4.#899JJJ>HJJJKKKHD) ( ( w||D*w*>??r%@@@  **"27<<j76J#K#K,0 2 2 2HH&((rw||D*w2FGG(,...D#$$T{{V3%$$$#$'(#(??V#;%(((#'((  N ! !2wh"? @ @ @ @ 99stA2EE*)E*-G GGG(( G76G7A0KK;K66K;O22 PPP P)(P)ctjt}tjd}|stjd}t t d|D}|D]} t t|dz}n;#ttf$r'}tj d|ztYd}~Vd}~wwxYwttjtj|dd }t|d zd d }||t%j||t)|S) aReturn 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*_*cDg|]}|ddSr r!rs rDrz sensors_fans..Tr"rCr#z ignoring %rNrFr$r'rr()r0rr|r6r2r5rrrrrr r rrsrr4rrsfanr5)rr6r:rrr;r<s rD sensors_fansrECs\  !$ ' 'C :;;I GIEFF s??Y???@@AAI < < #dXo..//GG!    M-#-~ > > > HHHH  RW__T%:%:FCC$&&& D8Ob??? Igl5'::;;;; 99s/BC CCcF t fd}dtjtD}|sdStjtt |d}||dz|dz}||dz|dz}||d z|d z}||d z}|| d |z|z }n;#t$rd }Yn-wxYwtt|dzd}|dkrdSd}|tjtdtjtd} | | dk}n6t|dzdd } | dkrd}n| dvrd}|r tj } nj|5|3 t||z dz} nO#t$rtj } Yn7wxYw|%t|dz} | dkr tj } n tj } tj|| |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|D]@}t|}|kr'|rt|n|cSAdS)zvAttempt to read the content of multiple files which may not exist. If none of them exist return None. rON)risdigitr)pathsrsrnulls rD multi_catz"sensors_battery..multi_catls\ : :DdT***Cd{{#&;;==9s3xxxc999trCchg|]/}|dsd|v-|0S)BATbattery)rr+rs rDrz#sensors_battery..vsG $ $ $! U8K8K $  " "  " " "rCNrz /energy_nowz /charge_nowz /power_nowz /current_nowz /energy_fullz /charge_fullz/time_to_empty_nowgY@rz /capacityr8rOz AC0/onlinez AC/onliner/statusrFr( discharging)chargingfullTi<)objectrr}POWER_SUPPLY_PATHrsrr2ZeroDivisionErrorrrr+rPOWER_TIME_UNLIMITEDPOWER_TIME_UNKNOWNsbattery) rKbatsr energy_now power_now energy_full time_to_emptyr_ power_pluggedonlinersecsleftrJs @rDsensors_batteryrbcs 88D $ $rz"344 $ $ $D t 7<<)6$<<? ; ;D } }J  | ~I) ~ ~KId%99::M:#9 j(;6GG    GGG c$,r:::;; b==4 M Y  & 55  & 4466F! TI%5AAAGGII ] " "!MM + + + M  ./  I$9 2: 1D899HH  2 2 21HHH 2  "}r)** a<<1H-  GX} = ==s$=C CC(F>>GGcg}tj}|D]C}|\}}}}}}|s|dvrd}tj||pd|||} || D|S)z:Return currently connected users as a list of namedtuples.)z:0.0z:0 localhostN)rusersrsuserr) rrawlistitemrttyhostnametstamp user_processrnts rDreresGjllG  9=6c8V\3   ~ % %"H ]4h D Dr NrCcLdtz}t|5}|D]b}|drKt|d}|a|ccdddSctd|z#1swxYwYdS)zAReturn the system boot time expressed in seconds since the epoch.rsbtimerNzline 'btime' not found in %s)rrrrrr BOOT_TIMEr)rsrrrs rD boot_timerps (( (D T  3a  Dx(( DJJLL..00344  33333333  *T 133 3 3333333333sABBB BcpdtjttDS)z7Returns a list of PIDs currently running on the system.cTg|]%}|t|&SrB)rHrrs rDrzpids..s+ L L Lq LCFF L L LrC)rr}rrrBrCrDrrs. L LBJq):):';';<< L L LLrCctj|sdS td|d}t|5}|D]R}|dr;t |d}||kccdddSStd|z#1swxYwYdS#ttf$r|tvcYSwxYw)zcCheck for the existence of a unix PID. Linux TIDs are not supported (always return False). FrrOsTgid:rNz'Tgid' line not found in %s) r pid_existsrrrrrr*EnvironmentErrorr)rrsrrtgids rDrtrts[  s # #!u !&5%6%6%6%6!EFFF G G G G G G G G G G!*- ! ! !$&&=  !s;#B0AB# B0B##B''B0*B'+B00!CCci}t}tD]} t|d|d5}|}dddn #1swxYwY|d}||dzd}t |d}|||<#ttf$rYwxYw|S)zsObtain a {pid: ppid, ...} dict for all running processes in one shot. Used to speed up Process.children(). r/statN)r<r) rrrrrrrrr!)rrrrdatarpardsetppids rDppid_mapr~ s! C!##Kvv   [[[###>?? 1vvxx               ::d##Dq ?((**DtAw<.wrapper%s 3t-d---f-- - 5 5 5tx44 4! 6 6 6$*55 5    7>>T->->->"IJJ :#DHdj999   s BB)) functoolswraps)rrs` rDwrap_exceptionsr!s:_S      NrCceZdZdZgdZdZdZeedZ eedZ eedZ dZ d Z ed Zd Zed Zed ZedZejdejzr edZedZedZed5dZedZedZer:eejdejdejdfdZ neZ er edZ!edZ"eejdfdZ#eejdfd Z$ed!Z%ed"Z&ed#Z'e(r)ed$Z)ejd%fd&Z*ed'Z+e,red(Z-ed)Z.e/ ed5d*Z0ed+Z1ed,Z2ed6d.Z3ed/Z4ed0Z5eejd1fd2Z6eejd3fd4Z7dS)7ProcesszLinux process implementation.)rr_ppidrv_cachecV||_d|_d|_t|_dSr)rrrrrv)rwrs rDrxzProcess.__init__;s+  +--rCcLtj|jd|jdS)z+Raise NSP if the process disappeared on us.rN)rrrvrrws rD _assert_alivezProcess._assert_aliveAs, 4,,,dhh788888rCc.t|jd|jd5}|}dddn #1swxYwY|d}||ddz|}||dzd}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. rrxNry(rr<rrrr}r$ttynr utime stime children_utimerchildren_stime create_time$cpu_num' blkio_ticks)rrvrrrfindr)rwrrzr{rrrs rD_parse_stat_filezProcess._parse_stat_fileGsn):):):DHHHE F F !6688D                zz$DIIdOOa',-dQhii&&((F q H QiF ayG bzG bzG &r   &r  #BZMI#BZM AAAct|jd|jd5}|cdddS#1swxYwYdS)zRead /proc/{pid}/stat file and return its content. The return value is cached in case oneshot() ctx manager is in use. rrON)rrvrrrwrs rD_read_status_filezProcess._read_status_filejs4+<+<+>## $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s&AA!Ac|j||j||j|dSr)rcache_activaterrrs rD oneshot_enterzProcess.oneshot_enter{sM ,,T222 --d333 ,,T22222rCc|j||j||j|dSr)rcache_deactivaterrrs rD oneshot_exitzProcess.oneshot_exitsM ..t444 //555 ..t44444rCcf|d}trt|}|S)Nr)rr"r )rwrs rDrz Process.names0$$&&v.  $<EFU## 6q 6 6D::<??? E8$8$=)>*8$8$  E E E -0VVVUUUFF"DEEE EsMB A+B + A85B 7A88B  B B )7C!! D +DD cr|}t|dtz }t|dtz }t|dtz }t|dtz }t|dtz }t|||||S)Nrrrrr)rrrr)rwrrrrrrs rDr zProcess.cpu_timess&&((fWo&&4fWo&&4v&6788;Fv&6788;Fvm,-- ;~~vNNNrCcPt|dS)zWhat CPU the process is on.rrrrs rDrzProcess.cpu_nums#4((**95666rCNcBtj|j||jSr)rwait_pidrr)rwtimeouts rDwaitz Process.waits 7DJ???rCct|d}tp t}|tz |zS)Nr)rrrorpr)rwctimebts rDrzProcess.create_times@d++--m<==  %)++ #r))rCc t|jd|jd5}d|ddD\}}}}}}}dddn #1swxYwYt |||||||S)Nrz/statmc<g|]}t|tzSrB)rrrs rDrz'Process.memory_info..s#EEEqQ("EEErCr)rrvrrrrx) rwrvmsr~rftextlibrzdirtys rD memory_infozProcess.memory_infos$*;*;*;TXXXF G G F1EEAJJLL,>,>,@,@!,DEEE 5CfdCu F F F F F F F F F F F F F F FCfdCu===sAA--A14A1s\nPrivate.*:\s+(\d+)s\nPss\:\s+(\d+)s\nSwap\:\s+(\d+)c|}|}ttt||dz}ttt||dz}ttt||dz}t ||||fzS)Nr)rrr8rrfindallry) rw _private_re_pss_re_swap_re basic_mem smaps_datarzr{r|s rDmemory_full_infozProcess.memory_full_infos((**I..00Jc#{22:>>??@@4GCc#wz::;;<>EDY#sD)99: :rCcd}|}|sgS|d}g}|d}|g}|||D]\}}|dd} |\} } } } } }n#t$r|dgz\} } } } } }YnwxYw|sd}nXtrt |}|}|drt|s |dd }| t | t | || d d| d d| d d| d d| dd| dd| dd| dd| dd| ddf |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. c3Ki}|D]}|dd}|dds.||fV||a t |ddz||d<#t $r0|ddrYt d|zwxYw||fVdS)Nrr]rrsVmFlags:z#don't know how to interpret line %r)rrpoprrr*r)r current_blockrzrrs rD get_blocksz'Process.memory_maps..get_blocksEs*!IID!ZZa00F!!9--d33 I,0022D9999%,,T2222I.1&)nnt.CDOO)III%ay33K@@I (&02ACG2H'I'I!I I%((**D111111s)!B  %C2C rNrrz[anon]rrsRss:sSize:sPss:s Shared_Clean:s Shared_Dirty:sPrivate_Clean:sPrivate_Dirty:s Referenced:s Anonymous:sSwap:) rrrr*r"r rrrrr)rwrrzrr9 first_linerheaderhfieldsrpermsoffsetdevrrss rD memory_mapszProcess.memory_maps<s+ 2 2 2(((**D  JJu%%EB1J'LM * 5- @ @    ,,tQ//'>BBc t|jd|jdS#ttf$rOt |jst |j|jt|j|j|j wxYw)Nrz/cwd) rrvrrr!rtrrrrrs rDcwdz Process.cwds F4+<+<+#eAh--U1X?? ?rCsThreads:\t(\d+)cz|}t||dSNr)rrr)rw_num_threads_rerzs rD num_threadszProcess.num_threadss6 %%''?**4003444rCctj|jd|jd}|g}d}|D] }|jd|jd|d} t |5}|}dddn #1swxYwYn#t$rd}YuwxYw|| ddzd}| d }t|d tz } t|d tz } tjt|| | } || "|r||S) Nrz/taskFz/task/rxTryr<rrr)rr}rvrsortrrrrrrrrrpthreadrrr) rw thread_idsr hit_enoent thread_idrrstrrrrs rDthreadszProcess.threadssZ0A0A0A4888 LMM  # # #I!!!4888YYY8E  ''*1))B***************$   "    BGGDMMA%&&'BXXd^^F&*%% 3E&*%% 3E_S^^UEBBF NN6 " " " "  !    s6B&''B B&B B&!B "B&& B54B5c4tj|jSr)r getpriorityrrs rDnice_getzProcess.nice_gets%dh///rCc6tj|j|Sr)r setpriorityr)rwr@s rDnice_setzProcess.nice_sets%dh666rCc4tj|jSr)rr6rrs rDcpu_affinity_getzProcess.cpu_affinity_gets-dh77 7rCsCpus_allowed_list:\t(\d+)-(\d+)c f|}||}|rRttt |ddt |dddzSttt t S)Nrr)rrr|rSrrr%)rw_rerzr.s rD_get_eligible_cpuszProcess._get_eligible_cpuss))++DKK%%E 9E#eAhqk"2"2Ca 4D4Dq4HIIJJJE#moo"6"677888rCc  tj|j|dS#ttf$r}t |ts|jt jkr|}tttt}|D]4}||vrt d|d|||vrt d|d|5d}~wwxYw)Nzinvalid CPU number z; choose between z CPU number z! is not eligible; choose between ) rproc_cpu_affinity_setrrr*rrr~rtuplerSrr%)rwr#r eligible_cpusall_cpuscpus rDcpu_affinity_setzProcess.cpu_affinity_sets *48T:::::Z(   c:.. E#)u|2K2K$($;$;$=$=M$U3}+?+?%@%@AAH#EEh..",*$'CC!8#9#99m33",*03]]!D#E#EE4 sCB+CCctj|j\}}tt |}t j||Sr)rr5renumr>rpionicerwioclassr@s rD ionice_getzProcess.ionice_gets=!1$(;;NGU$W--?7E22 2rCc|d}|r"|ttfvrtd|z|dks|dkrtdtj|j||S)Nrz%r ioclass accepts no valuerzvalue not in 0-7 range)r)r&r*rproc_ioprio_setrr s rD ionice_setzProcess.ionice_setsq} J%68I$JJJ !>!HIIIqyyEAII !9:::''5AA ArCc|jdkrtd |t|j|St|dkrtdt |zt|j||dS#t $rO}|jt jkr4t|jr t|j|j |j d}~wwxYw)Nrz)can't use prlimit() against PID 0 processr<z4second argument must be a (soft, hard) tuple, got %s) rr*rrrrrENOSYSrtrrr)rwrrrs rDrlimitzProcess.rlimits x1}} !LMMM >"48Y7776{{a''(%'+F||4555DHi88888   9 ,,DH1E1E,($*djIII  sA=AA== CA CCc|d}tr|}t|dS)Nr?)rr"r PROC_STATUSESr)rwletters rDrzProcess.statussC&&((2  %]]__F  ---rCcg}tj|jd|jd}d}|D]}|jd|jd|} t |}|dr%t |r|jd|jd|} t|5}t| d}t| dd} dddn #1swxYwYt| } t|t|t|| | } | | O#t$rd}Y^wxYwd#ttf$rd}Yzt $r!} | jt"jkrYd} ~ d} ~ wwxYw|r||S) NrrzFr{z/fdinfo/rrT)rr}rvrrrrrrrrrrrrrr!rrr~r) rwrrrrtrrsrposrwrvrrs rD open_fileszProcess.open_files&sj ):):):DHHHEFF " /" /B$($5$5$5txxxDD /~~??3''/M$,?,?/)))4888RR9D /(..D!"%ajjll&8&8&:&:1&=">">C$' (:(:(<(>_>&' 'BJ'?@@" #677#$899  ; ; ;  ; ;8'D A A  A FFF_F#-2:.G#H#H @ @ @_ @*4"*5H*I*I555_5_600_077_7!  8 8  8%"*%HII 9 9 9 9     &B  3 3  3  B B  B      2.._.))_)V_ KK_K44_4&BJ'DEEDDD_D &BJ'DEEDDD_DDDrCrrr.)F)r __future__rrr0rrr6rr,rorsys tracebackrrrrrrr rr rr r r rrrrrrrrrrrrrrr_compatrrrr r!r" version_infor __extra__all__rUrsrKr0r1hasattrr3r2rTrr)r getpagesizerror byteorderrr AF_PACKETr;IntEnumrr:r&r'r(r)r>globalsr __members__STATUS_RUNNINGSTATUS_SLEEPINGSTATUS_DISK_SLEEPSTATUS_STOPPEDSTATUS_TRACING_STOP STATUS_ZOMBIE STATUS_DEADSTATUS_WAKE_KILL STATUS_WAKING STATUS_IDLE STATUS_PARKEDrr*r+r,r-r.r/r0r1r2r3r4rr\rhrrrxrryr}rrrrrrrrr Exception print_excrrresource ImportErrorrCDLLrr1dirrr rr r%r1rArHr[ net_if_addrsr`rbrrrr disk_usagerrrArErbrerprrtr~rrrBrCrDrTsc  %$   ######""""""######))))))!!!!!!$$$$$$""""""++++++$$$$$$$$$$$$''''''"""""" ((((((''''''""""""""""""""""""&&&&&&$$$$$$''''''vKKKK D 6 6 6". GNN+ibikk9 : : wt%67774!899 688bj&& !: ! # #  'BB4 ) <GG DL"+SS1A-B-B!CEEM#G<OOT\  GIIZ+,,,     "    $        !         "  "           !         *   KKK L L *    J<<< > > z&>?? :j$,1G"G H H JJJKK J-*?!@!@@ B B j66677 J{""" # # (   $$$& 00 00!     K!!!!KKKI; ;(:;;CcJJIIIK 8       888MMM 6;tt , , ,DwtY8 8 8 8 88< FFCCIIFFFHHH111hwBwBwBt2@2@2@t    (:'''T===*7>>;<<3 =>>3@W^^O$$    &      I   ggggggggT{}} '''' """J4 \\\\~####Vnnnb@V>V>V>|$ 3 3 3&MMM !!!@,*tDtDtDtDtDftDtDtDtDtDs$= M +M76M7=N+N21N2