U g+ @stdZddlZddlZddlZddlZddlZddlmZddlmZddlm Z ddlm Z ddlm Z dd l m Z dd l mZdd l mZdd l mZdd l mZddl mZddl mZerddlmZe rddlZndZddddgZddZedk r.eedr.ededdejDZddZnddZddeje edeje!ej"efddZ#ddZ$e d dZ%dS)!z%Routines common to all posix systems.N)MACOSTimeoutExpired)memoize) sdiskusage) usage_percent)PY3)ChildProcessError)FileNotFoundError)InterruptedError)PermissionError)ProcessLookupError)unicode) _psutil_osx pid_existswait_pid disk_usageget_terminal_mapcCsP|dkr dSzt|dWn*tk r2YdStk rFYdSXdSdS)z6Check whether pid exists in the current process table.rTFN)oskillrr )pidr?/opt/hc_python/lib64/python3.8/site-packages/psutil/_psposix.pyr(sSignals NegsignalcCsg|]}|j|j fqSr)namevalue).0xrrr Bsr cCs(z t|WStk r"|YSXdS)z+Convert a negative signal value to an enum.N)r ValueErrornumrrrnegsig_to_enumEs r$cCs|S)Nrr"rrrr$Ns monotoniccsdkrd}t|d} d} dk r8| tjO} fdd} zt| \} } WnBtk r| | } YqPtk r|r| | } qYdSX| dkr| | } qPt| rt| St| rt t |  Std| qPdS)aWait for a process PID to terminate. If the process terminated normally by calling exit(3) or _exit(2), or by returning from main(), the return value is the positive integer passed to *exit(). If it was terminated by a signal it returns the negated value of the signal which caused the termination (e.g. -SIGTERM). If PID is not a children of os.getpid() (current process) just wait until the process disappears and return None. If PID does not exist at all return None immediately. If *timeout* != None and process is still alive raise TimeoutExpired. timeout=0 is also possible (either return immediately or raise). rzcan't wait for PID 0g-C6?Ncs6dk r kr td||ddS)N)rrg{Gz?r)interval_min_sleep_timerr proc_nameZstop_attimeoutrrsleepws  zwait_pid..sleepzunknown process exit status %r) r!rWNOHANGwaitpidr r WIFEXITED WEXITSTATUS WIFSIGNALEDr$WTERMSIG)rr-r,_waitpidr+r)r*Z _pid_existsmsgr'flagsr.Zretpidstatusrr(rrRs2        c Cstrt|}ndzt|}WnTtk rrt|trlz|t}Wntk r^YnXt|}nYnX|j |j }|j |j }|j |j }||}t rt||}||}t||dd}t||||dS)a.Return disk usage associated with path. Note: UNIX usually reserves 5% disk space which is not accessible by user. In this function "total" and "used" values reflect the total and used disk space whereas "free" and "percent" represent the "free" and "used percent" user disk space. r)Zround_)totalusedfreepercent)r rstatvfsUnicodeEncodeError isinstancerencodesysgetfilesystemencodingf_blocksf_frsizef_bfreef_bavailrrZdisk_usage_usedrr)pathstr9Z avail_to_rootZ avail_to_userr:Z total_userZusage_percent_userrrrrs4       c Cs`i}tdtd}|D]>}||ks0t|z||t|j<Wqtk rXYqXq|S)zNGet a map of device-id -> path as a dict. Used by Process.terminal(). z /dev/tty*z /dev/pts/*)globAssertionErrorrstatst_rdevr )retZlsrrrrrs)&__doc__rIrsignalrAtimeZ_commonrrrrrZ_compatr r r r r rrrenum__all__rhasattrIntEnumdictrrr$r0getattrminr.rrrrrrrsT                  _5