U _m@s^dZddlZddlZddlZddlZddlZddlmZddlmZddlm Z ddlm Z ddl m Z dd l m Z dd l mZdd l mZdd l mZdd l mZddl mZejdkrddlZndZddddgZddZedk reedrededdejDZddZnddZddejeedejeej efddZ!ddZ"eddZ#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_mapcCsP|dkr dSzt|dWn*tk r2YdStk rFYdSXdSdS)z6Check whether pid exists in the current process table.rTFN)oskillr r )pidrB/opt/alt/python38/lib64/python3.8/site-packages/psutil/_psposix.pyr"sSignals NegsignalcCsg|]}|j|j fqSr)namevalue).0xrrr <sr cCs(z t|WStk r"|YSXdS)z+Convert a negative signal value to an enum.N)r ValueErrorZnumrrrnegsig_to_enum>s r#cCs|S)Nrr"rrrr#Es monotonicc sdkrtdd}d} dk r4| tjO} fdd} zt| \} } WnBtk r|| |}YqLtk r|r| |}qYdSX| 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?Ncs6dk r 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-ZretpidZstatusrr'rrIs0        c Cstrt|}ndzt|}WnTtk rrt|trlz|t}Wntk r^YnXt|}nYnX|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_)totalusedZfreeZpercent)r rstatvfsUnicodeEncodeError isinstancerencodesysgetfilesystemencodingf_blocksf_frsizef_bfreef_bavailrr)pathstr5Z avail_to_rootZ avail_to_userr6Z total_userZusage_percent_userrrrrs0      c CsPi}tdtd}|D].}z||t|j<Wqtk rHYqXq|S)zMGet a map of device-id -> path as a dict. Used by Process.terminal() z /dev/tty*z /dev/pts/*)globrstatst_rdevr )ZretZlsrrrrrs)$__doc__rCrsignalr;timeZ_commonrrrrZ_compatrr r r r r r version_infoenum__all__rhasattrIntEnumdictrrr#r/getattrminr-rrrrrrrsL                 X1