a M_m@sZdZddlZddlZddlZddlZddlZddlmZddlmZddlm Z ddlm Z ddl m Z dd l m Z dd l mZdd l mZdd l mZdd l mZddl mZejdkrddlZndZgdZddZedureedrededdejDZddZnddZddejeedejeej efddZ!ddZ"edd Z#dS)!z%Routines common to all posix systems.N)memoize) sdiskusageTimeoutExpired) usage_percent)ChildProcessError)FileNotFoundError)InterruptedError)PermissionError)ProcessLookupError)PY3)unicode)) pid_existswait_pid disk_usageget_terminal_mapcCsL|dkr dSzt|dWn&ty0YdStyBYdS0dSdS)z6Check whether pid exists in the current process table.rTFN)oskillr r )pidr5/usr/lib64/python3.9/site-packages/psutil/_psposix.pyr"s  rSignals NegsignalcCsg|]}|j|j fqSr)namevalue).0xrrr <r cCs&z t|WSty |YS0dS)z+Convert a negative signal value to an enum.N)r ValueErrorZnumrrrnegsig_to_enum>s  r$cCs|S)Nrr#rrrr$Es monotonicc sdkrtdd}d} dur4| tjO} fdd} zt| \} } Wn>tyz| |}YqLty|r| |}qYdS0| dkr| |}qLqLt| rt| St| rt t |  Std| qLdS)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?Ncs6dur kr td||ddS)N)rrg{Gz?r)interval_min_sleep_timerr proc_nameZstop_attimeoutrrsleephs  zwait_pid..sleepzunknown process exit status %r) r"rWNOHANGwaitpidr r WIFEXITED WEXITSTATUS WIFSIGNALEDr$WTERMSIG) rr-r,Z_waitpidr+r)r*Z _pid_existsr'flagsr.Zretpidstatusrr(rrIs0          rc Cstrt|}n`zt|}WnPtynt|trhz|t}WntyZYn0t|}nYn0|j |j }|j |j }|j |j }||}||}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_bavailrr)pathstr7Z avail_to_rootZ avail_to_userr8Z total_userZusage_percent_userrrrrs*        rc CsNi}tdtd}|D],}z||t|j<WqtyFYq0q|S)zMGet a map of device-id -> path as a dict. Used by Process.terminal() z /dev/tty*z /dev/pts/*)globrstatst_rdevr )retZlsrrrrrs r)$__doc__rGrsignalr?timeZ_commonrrrrZ_compatrr r r r r r version_infoenum__all__rhasattrIntEnumdictrrr$r0getattrminr.rrrrrrrsJ                X1