
    /h                        d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlmZ ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddlm"Z" ddlm#Z# ddlm$Z$ ddlm%Z% ddlm&Z& ddlm'Z' ddlm(Z( ddlm)Z) ddlm*Z* ddlm+Z+ ddlm,Z, ddlm-Z- ddlm.Z. ddlm/Z/ ddlm0Z0 dd lm1Z1 dd!lm2Z2 dd"lm3Z3 dd#lm4Z4 dd$lm5Z5 dd%lm6Z6 dd&lm7Z7 dd'lm8Z8 dd(lm9Z9 dd)lm:Z: dd*lm;Z;  G d+ d,e.          Z< G d- d.e.          Z=dS )/Tests for psutil.Process class.    N)mock)AIX)BSD)LINUX)MACOS)NETBSD)OPENBSD)OSX)POSIX)WINDOWS)	open_text)
CI_TESTING)GITHUB_ACTIONS)GLOBAL_TIMEOUT)HAS_CPU_AFFINITY)HAS_ENVIRON)
HAS_IONICE)HAS_MEMORY_MAPS)HAS_PROC_CPU_NUM)HAS_PROC_IO_COUNTERS)
HAS_RLIMIT)HAS_THREADS)MACOS_11PLUS)PYPY)
PYTHON_EXE)PYTHON_EXE_ENV)PsutilTestCase)
ThreadTask)
call_until)copyload_shared_lib)create_c_exe)create_py_exe)process_namespace)pytestreap_children)retry_on_failure)sh)skip_on_access_denied)skip_on_not_implemented)wait_for_pidc                      e Zd ZdZd Zd Zd Zd Zd Ze	j
                            e d          d	             Zd
 Ze	j
                            ed          d             Zd Zd Zd Zd Zd Zd Zd Ze	j
                            e d          d             Zd Ze	j
                            e d          d             Ze	j
                            e d           ee          d                         Ze	j
                            e  d          e	j
                            e d          d                         Z!e	j
                            e  d          e	j
                            e" d          d                         Z#e	j
                            e$ d          d             Z%e	j
                            e$ d          d              Z&e	j
                            e$ d          d!             Z'e	j
                            e$ d          d"             Z(e	j
                            e$ d          d#             Z)d$ Z*e	j
                            e" d%          d&             Z+e	j
                            e, d          d'             Z- e.             e/e0          e	j
                            e, d          d(                                     Z1 e.            d)             Z2d* Z3e	j
                            e4 d          d+             Z5e	j
                            e4 d          d,             Z6d- Z7d. Z8d/ Z9d0 Z:e	j
                            e;d1          d2             Z<d3 Z=e	j
                            e;d4          d5             Z>e	j
                            e d          d6             Z?e	j
                            e d          d7             Z@d8 ZAd9 ZBd: ZCd; ZDd< ZEe	j
                            eF d          d=             ZGe	j
                            eF d          d>             ZHe	j
                            eF d          d?             ZIe	j
                            eJd@          dA             ZKe	j
                            eJd@          dB             ZLe	j
                            e d          dC             ZM ee          e	j
                            eNpedD          dE                         ZOdF ZPdG ZQdH ZR e.            dI             ZSdJ ZTdK ZUdL ZVdM ZWdN ZXdO ZYdP ZZdQ Z[dR Z\dS Z]dT Z^e	j
                            e d          dU             Z_e	j
                            e d          dV             Z`e	j
                            e d          dW             ZadX ZbdY Zce	j
                            ed d          dZ             Zee	j
                            ed d          e	j
                            e d          e	j
                            efd[          e	j
                            ed\          d]                                                 Zgd^S )_TestProcessr   c                      | j         |i |}	 t          j        |j                  S # t          j        $ r |                     |j                    w xY wN)spawn_testprocpsutilProcesspidNoSuchProcessassertPidGone)selfargskwargssprocs       L/var/www/html/venv/lib/python3.11/site-packages/psutil/tests/test_process.pyspawn_psproczTestProcess.spawn_psprocL   sg    ##T4V44	>%),,,# 	 	 	uy)))	s	   ( +Ac                     t          j                    }|j        t          j                    k    sJ t          j        t                    5  d|_        d d d            d S # 1 swxY w Y   d S )N!   )r2   r3   r4   osgetpidr%   raisesAttributeErrorr7   ps     r;   test_pidzTestProcess.test_pidV   s    Nu	####]>** 	 	AE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A  A$'A$c                    |                                  }|                                 |                                }t          r|t          j        k    sJ n|t          j         k    sJ |                     |           d S r0   )r<   killwaitr   signalSIGTERMSIGKILLassertProcessGoner7   rD   codes      r;   	test_killzTestProcess.test_kill\   sz    	vvxx 	+6>)))))FN?****q!!!!!    c                    |                                  }|                                 |                                }t          r|t          j        k    sJ n|t          j         k    sJ |                     |           d S r0   )r<   	terminaterH   r   rI   rJ   rL   rM   s      r;   test_terminatezTestProcess.test_terminatef   sz    	vvxx 	+6>)))))FN?****q!!!!!rP   c                    t           rt          j        nt          j        }|                                 }|                    |           |                                }t          r	||k    sJ n	|| k    sJ |                     |           d S r0   )	r   rI   rK   rJ   r<   send_signalrH   r   rL   )r7   sigrD   rN   s       r;   test_send_signalzTestProcess.test_send_signalp   s     %9fnn6>	cvvxx 	 3;;;;;C4<<<<q!!!!!rP   z	not POSIX)reasonc                 h   t           j        }|                                 }t          j        dt
                    5  t          j        t          j	                  5  |
                    |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                                 }t          j        dt                    5  t          j        t          j                  5  |
                    |           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nzpsutil.os.killside_effect)rI   rJ   r<   r   patchProcessLookupErrorr%   rA   r2   r5   rU   PermissionErrorAccessDenied)r7   rV   rD   s      r;   test_send_signal_mockedz#TestProcess.test_send_signal_mocked{   s   nZ(6HIII 	# 	#v344 # #c"""# # # # # # # # # # # # # # #	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# Z(oFFF 	# 	#v233 # #c"""# # # # # # # # # # # # # # #	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#sk   BA=1B=B	BB	BBBD'-DD'D	D'D	D''D+.D+c                    t           ddg}|                     |          }|                                }|dk    sJ |                     |           t           ddg}|                     |t          j                  }|                                }|dk    sJ |                     |           t           ddg}|                     |          }|                                }|dk    sJ |                     |           t           dd	g}|                     |          }|                                }|dk    sJ |                     |           d S )
N-cpassr   z1 / 0)stderr   zimport sys; sys.exit(5);   zimport os; os._exit(5);)r   r<   rH   rL   
subprocessPIPE)r7   cmdrD   rN   s       r;   test_wait_exitedzTestProcess.test_wait_exited   sG    4(c""vvxxqyyyyq!!!4)c*/::vvxxqyyyyq!!!4!;<c""vvxxqyyyyq!!!4!:;c""vvxxqyyyyq!!!!!rP   zfails on NETBSDc                    |                                  }t          rA|                    t          j                   t          j        t          j                  5  |	                    d           d d d            n# 1 swxY w Y   |                    t          j
                   t          j        t          j                  5  |	                    d           d d d            n# 1 swxY w Y   |                    t          j                   |	                                t          j         k    sJ |	                                t          j         k    sJ d S |                                 t          j        t          j                  5  |	                    d           d d d            n# 1 swxY w Y   |                                 t          j        t          j                  5  |	                    d           d d d            n# 1 swxY w Y   |                                 |	                                t          j        k    sJ |	                                t          j        k    sJ d S )NMbP?)timeout)r<   r   rU   rI   SIGSTOPr%   rA   r2   TimeoutExpiredrH   SIGCONTrJ   suspendresumerR   rC   s     r;   test_wait_stoppedzTestProcess.test_wait_stopped   s    	. MM&.)))v455 & &u%%%& & & & & & & & & & & & & & &MM&.)))v455 & &u%%%& & & & & & & & & & & & & & &MM&.)))6688....6688......IIKKKv455 & &u%%%& & & & & & & & & & & & & & &HHJJJv455 & &u%%%& & & & & & & & & & & & & & &KKMMM6688v~----6688v~------sH   A==BBC((C,/C,F33F7:F70HHHc                    |                                  \  }}t          j        t          j                  5  |                    d           d d d            n# 1 swxY w Y   t          j        t          j                  5  |                    d           d d d            n# 1 swxY w Y   |                                 |                                 |                                }|                                }t          r|t          j	         k    sJ |J d S |t          j	        k    sJ |t          j	        k    sJ d S )N{Gz?)
spawn_children_pairr%   rA   r2   ro   rH   rR   r   rI   rJ   )r7   child
grandchild	child_retgrandchild_rets        r;   test_wait_non_childrenz"TestProcess.test_wait_non_children   s    !4466z]6011 	 	JJt	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]6011 	" 	"OOD!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	JJLL	#** 	///// ")))))..........s#   AAAB##B'*B'c                    |                                  }|                                 t          j        t          j                  5  |                    d           d d d            n# 1 swxY w Y   t          j        t          j                  5  |                    d           d d d            n# 1 swxY w Y   t          j        t                    5  |                    d           d d d            d S # 1 swxY w Y   d S )Nru   r   )r<   namer%   rA   r2   ro   rH   
ValueErrorrC   s     r;   test_wait_timeoutzTestProcess.test_wait_timeout   s   	]6011 	 	FF4LLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]6011 	 	FF1III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]:&& 	 	FF2JJJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s6   A))A-0A-B44B8;B8C;;C?C?c                    |                                  }t          j        t          j                  5  |                    d           d d d            n# 1 swxY w Y   |                                 t          j                    t          z   }t          j                    |k     rC	 |                    d          }nA# t          j        $ r Y nw xY wt          j                    |k     C| 	                    d          t          r|t          j         k    sJ n|t          j        k    sJ |                     |           d S )Nr   rm   )r<   r%   rA   r2   ro   rH   rG   timer   failr   rI   rK   rJ   rL   )r7   rD   stop_atrN   s       r;   test_wait_timeout_nonblockingz)TestProcess.test_wait_timeout_nonblocking   sf   ]6011 	 	FF1III	 	 	 	 	 	 	 	 	 	 	 	 	 	 		)++.ikkG##vvayy(   	 ikkG## ))I&&& 	*FN?*****6>))))q!!!!!s#   AAA'B= =CCc                    t          j                    }|                    d           |                    d           t          d          D ]7}|                    d           }t	          |t
                    sJ |dk    sJ 8t          j        t                    5  |                    d           d d d            d S # 1 swxY w Y   d S )Nrl   )intervald           r}   )	r2   r3   cpu_percentrange
isinstancefloatr%   rA   r   )r7   rD   _percents       r;   test_cpu_percentzTestProcess.test_cpu_percent   s   N	u%%%	u%%%s 	" 	"AmmTm22Ggu-----c>>>>>]:&& 	' 	'MM2M&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's    CCCc                     t          j        dd           5 }t          j                                                     |j        sJ 	 d d d            d S # 1 swxY w Y   d S )Nzpsutil.cpu_count)return_value)r   r\   r2   r3   r   called)r7   ms     r;   test_cpu_percent_numcpus_nonez)TestProcess.test_cpu_percent_numcpus_none   s    Z*>>> 	!N((***8OOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   /AAAc           
         t          j                                                    }|j        dk    s
J |            |j        dk    s
J |            |j        dk    s
J |            |j        dk    s
J |            t          r|j        dk    s
J |            |j	        D ]7}t          j        dt          j        t          ||                               8d S )Nr   z%H:%M:%S)r2   r3   	cpu_timesusersystemchildren_userchildren_systemr   iowait_fieldsr   strftime	localtimegetattr)r7   timesr~   s      r;   test_cpu_timeszTestProcess.test_cpu_times  s      **,,zS   %   |s"""E""""c)))5)))$+++U+++ 	.<3&&&&&&M 	L 	LDM*dnWUD5I5I&J&JKKKK	L 	LrP   c                    d } |             t          j                                                    }t          j                    }|                     |j        |j        d           |                     |j        |j        d           d S )Nc                      t          j                    j        dz   } t          j                    j        | k     r5t          d          D ]}|dz  }t          j                    j        | k     3d S d S )Ng?i    )r?   r   r   r   )r   xs     r;   	waste_cpuz/TestProcess.test_cpu_times_2.<locals>.waste_cpu  sh    hjjo+G(**/G++v  A!GAA (**/G++++++rP   皙?)delta)r2   r3   r   r?   r   assertAlmostEqualr   r   )r7   r   abs       r;   test_cpu_times_2zTestProcess.test_cpu_times_2  s    	 	 	 		N&&((HJJqvqvS999qx=====rP   znot supportedc                    t          j                    }|                                }|dk    sJ t          j                    dk    r|dk    sJ |                                t	          t          j                              v sJ d S Nr   re   )r2   r3   cpu_num	cpu_countr   )r7   rD   nums      r;   test_cpu_numzTestProcess.test_cpu_num  sz    Niikkaxxxx""!8888yy{{eF$4$6$677777777rP   c                 Z   |                                  }t          j                    }|                                }t          ||z
            }|dk    r|                     d| d| d|           t          j        dt          j        |                                                     d S )Nr   z
expected: z	, found: z, difference: z%Y %m %d %H:%M:%S)r<   r   create_timeabsr   r   r   )r7   rD   nowr   
differences        r;   test_create_timezTestProcess.test_create_time%  s    ikkmmoo
 s*++
>>))!S ! !; ! !! !   	)4>!--//+J+JKKKKKrP   z
POSIX onlyc                    t          j                                                    }|Y	 t          j                            t          d                    }||k    sJ d S # t          $ r t          j	        d          w xY wd S )Nttyzcan't rely on `tty` CLI)
r2   r3   terminalr?   pathrealpathr)   RuntimeErrorr%   skip)r7   r   r   s      r;   test_terminalzTestProcess.test_terminal7  s    >##,,..'g&&r%yy11
  3	   = = =k";<<<=  s   ,A A>)only_ifc                    t          j                    }|                                }t          t          d          5 }|                                 d d d            n# 1 swxY w Y   |                                }t          sWt          sP|j        |j        k    sJ |j	        |j	        k    sJ t          r$|j        |j        k    sJ |j        |j        k    sJ n$|j        |j        k    sJ |j        |j        k    sJ |                                }t          |                                 d          5 }|                    t#          ddz  d                     d d d            n# 1 swxY w Y   |                                }|j	        |j	        k    sJ |j        |j        k    sJ |j        |j        k    sJ |j        |j        k    sJ t          r$|j        |j        k    sJ |j        |j        k    sJ t%          t'          |                    D ],}t          r|dk    r||         dk    sJ ||         dk    sJ -d S )Nrbwbr   i@B asciir   r   )r2   r3   io_countersopenr   readr   r   
read_countwrite_countr   
read_charswrite_chars
read_byteswrite_bytes
get_testfnwritebytesr   len)r7   rD   io1fio2is         r;   test_io_counterszTestProcess.test_io_countersC  s    Nmmoo*d## 	qFFHHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	mmoo 	63 	6>CN2222?co5555 :~6666#/9999>S^3333?co5555 mmoo$//##T** 	3aGGE#-11222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3mmoo#/1111#/1111~////~//// 	4?S_4444>S^3333 s3xx 	 	A qAvvq6Q;;;;q6Q;;;;;	 	s#   AA"%A"5'E((E,/E,z
linux onlyc                    fd}t          j                    t          s*                                d         t           j        k    sJ t           j        dk    sJ t           j        dk    sJ t           j        dk    sJ t           j        dk    sJ                                 }|                     ||                               t           j                   t                                                    t           j        dfk    sJ t          j        t                    5                      t           j        d           d d d            n# 1 swxY w Y                       t           j                   t                                                    t           j        dfk    sJ                     t           j        d           t                                                    t           j        dfk    sJ t          j        t                    5                      t           j        d           d d d            n# 1 swxY w Y   	                     t           j        d           n# t           j        $ r Y nw xY wt          j        t          d	
          5                      t           j        d           d d d            n# 1 swxY w Y   t          j        t          d	
          5                      t           j        d           d d d            n# 1 swxY w Y   t          j        t          d
          5                      d           d d d            d S # 1 swxY w Y   d S )Nc                 b    | \  }}|t           j        k    rd}                    ||           d S Nr   )r2   IOPRIO_CLASS_NONEionice)initioclassvaluerD   s      r;   cleanupz.TestProcess.test_ionice_linux.<locals>.cleanupn  s9    !NGU&222HHWe$$$$$rP   r   re   r         r      zioclass accepts no valuematchz$'ioclass' argument must be specified)r2   r3   r   r   r   IOPRIO_CLASS_RTIOPRIO_CLASS_BEIOPRIO_CLASS_IDLE
addCleanuptupler%   rA   r   r_   )r7   r   r   rD   s      @r;   test_ionice_linuxzTestProcess.test_ionice_linuxk  sc   	% 	% 	% 	% 	% N 	=88::a=F$<<<<<'1,,,,%****%****'1,,,,xxzz&&& 	
)***QXXZZ  V%=q$AAAAA]:&& 	8 	8HHV-QH777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	
'(((QXXZZ  V%;Q$?????	'q111QXXZZ  V%;Q$?????]:&& 	6 	6HHV+1H555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6	HHV+1H5555" 	 	 	D	 ]:-GHHH 	2 	2HHV-q111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2]:-GHHH 	2 	2HHV-q111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2]D
 
 
 	 	 HH1H	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sl   ("EEE "III!I< <JJ,!KK K?!L,,L03L0M66M:=M:z!not supported on this win versionc                    t          j                    }t          s$|                                t           j        k    sJ |                                }|                     |j        |           |                    t           j                   |                                t           j        k    sJ |                    t           j                   |                                t           j        k    sJ 	 |                    t           j                   |                                t           j        k    sJ n# t           j	        $ r Y nw xY wt          j        t          d          5  |                    t           j        d           d d d            n# 1 swxY w Y   t          j        t          d          5  |                    t           j        dz              d d d            d S # 1 swxY w Y   d S )Nz&value argument not accepted on Windowsr   re   r   zis not a valid priority)r2   r3   r   r   IOPRIO_NORMALr   IOPRIO_VERYLOW
IOPRIO_LOWIOPRIO_HIGHr_   r%   rA   	TypeErrorr   )r7   rD   r   s      r;   test_ionice_winzTestProcess.test_ionice_win  sA   
 N 	688::!55555xxzz$''' 	
&'''xxzzV22222	"###xxzzV.....	4HHV'((( 88::!333333 " 	 	 	D	
 ]E
 
 
 	4 	4 HHV)H333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 ]:-FGGG 	- 	-HHV'!+,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s6   5D9 9E
E)"FFF=#G--G14G1c                 8   dd l }t          j        t          j                              }d t          t                    D             }|s
J |            |D ]}t          t          |          }|dk    sJ |t          |          v rM|t          ||          k    sJ t          rN|                    |          |	                    |          k    sJ }|                    |          }t          |          dk    sJ |d         dk    sJ |d         dk    sJ d S )Nr   c                 <    g | ]}|                     d           |S )RLIMIT)
startswith.0r   s     r;   
<listcomp>z/TestProcess.test_rlimit_get.<locals>.<listcomp>  s)    BBBq1<<+A+ABBBBrP   r   r}   re   )resourcer2   r3   r?   r@   dirr   r   rlimit	getrlimitr   )r7   r   rD   namesr~   r   rets          r;   test_rlimit_getzTestProcess.test_rlimit_get  s-   N29;;''BBCKKBBBe 	$ 	$DFD))EA::::s8}}$$$ 7 77777  xx(*<*<U*C*CCCCCChhuoo3xx1}}}}1v||||1v|||||	$ 	$rP   c                 4   |                                  }|                    t          j        d           |                    t          j                  dk    sJ t          ret          j        t          d          5  t          j        	                    d                              d           d d d            n# 1 swxY w Y   t          j        t                    5  |                    t          j        d           d d d            d S # 1 swxY w Y   d S )N)rf   rf   zcan't use prlimitr   r   )rf   rf   rf   )
r<   r   r2   RLIMIT_NOFILEr   r%   rA   r   _psplatformr3   rC   s     r;   test_rlimit_setzTestProcess.test_rlimit_set  so   	%v...xx,--7777  	8z1DEEE 8 8"**1--44Q7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8]:&& 	6 	6HHV)9555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s$   <3B;;B?B?!DDDc                    t          j                    }|                                 }|                    t           j                  \  }}	 |                    t           j        d|f           t          |d          5 }|                    d           d d d            n# 1 swxY w Y   t          j        t                    5 }t          |d          5 }|                    d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |j
        j        t          j        k    sJ 	 |                    t           j        ||f           |                    t           j                  ||fk    sJ d S # |                    t           j        ||f           |                    t           j                  ||fk    sJ w xY w)N   r   s   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXs  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX)r2   r3   r   r   RLIMIT_FSIZEr   r   r%   rA   OSErrorr   errnoEFBIG)r7   rD   testfnsofthardr   excs          r;   test_rlimitzTestProcess.test_rlimit  sR   N""XXf122
d	AHHV(4,777fd## %q$$$% % % % % % % % % % % % % % % w'' )3&$'' )1GGK((() ) ) ) ) ) ) ) ) ) ) ) ) ) )) ) ) ) ) ) ) ) ) ) ) ) ) ) ) 9?ek11111HHV(4,77788F/00T4L@@@@@@ HHV(4,77788F/00T4L@@@@@@@@sy   2F  =BF  B##F  &B#'F  DC6*D6C:	:D=C:	>DF  DF  DF   AGc                    t          j                    }|                    t           j                  \  }}	 |                    t           j        d|f           |                    t           j        t           j        |f           t          |                                 d          5 }|                    d           d d d            n# 1 swxY w Y   |                    t           j        ||f           |                    t           j                  ||fk    sJ d S # |                    t           j        ||f           |                    t           j                  ||fk    sJ w xY w)Nr  r   s   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX)r2   r3   r   r	  RLIM_INFINITYr   r   r   )r7   rD   r  r  r   s        r;   test_rlimit_infinityz TestProcess.test_rlimit_infinity  s|    NXXf122
d	AHHV(4,777HHV(6+?*FGGGdoo''.. %!$$$% % % % % % % % % % % % % % % HHV(4,77788F/00T4L@@@@@@ HHV(4,77788F/00T4L@@@@@@@@s1   A0D 'C	=D 	CD CD AE*c                     t          j                    }|                    t           j                  \  }}|t           j        k    sJ |                    t           j        ||f           d S r0   )r2   r3   r   r	  r  )r7   rD   r  r  s       r;   test_rlimit_infinity_valuez&TestProcess.test_rlimit_infinity_value  s^     NXXf122
dv+++++	$tTl33333rP   c                 j   t          j                    }t          r=	 |                                }n;# t           j        $ r t          j        d          w xY w|                                }t                      5  |                                }||dz   k    sJ 	 d d d            d S # 1 swxY w Y   d S )N$on OpenBSD this requires root accessre   )r2   r3   r
   num_threadsr_   r%   r   r   )r7   rD   step1step2s       r;   test_num_threadszTestProcess.test_num_threads	  s    N 	$J& J J Jk"HIIIJ MMOOE\\ 	& 	&MMOOEEAI%%%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s   1 $A: B((B,/B,zWINDOWS onlyc                 `    t          j                    }|                                dk    sJ d S r   )r2   r3   num_handlesrC   s     r;   test_num_handleszTestProcess.test_num_handles  s0     N}}""""""rP   c                     t          j                    }t          r=	 |                                }n;# t           j        $ r t          j        d          w xY w|                                }t                      5  |                                }t          |          t          |          dz   k    sJ |d         }|j	        |d         k    sJ |j
        |d         k    sJ |j        |d         k    sJ 	 d d d            d S # 1 swxY w Y   d S )Nr  re   r   r   )r2   r3   r
   threadsr_   r%   r   r   r   id	user_timesystem_time)r7   rD   r  r  athreads        r;   test_threadszTestProcess.test_threads   s]   N 	 J		& J J Jk"HIIIJ IIKKE\\ 	5 	5IIKKEu::Ua////AhG:++++$
2222&'!*44444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s   1 $A:A;DD
Dc                    |                                  }t          r=	 |                                 n'# t          j        $ r t          j        d          w xY wt          |                                j	        t          d |                                D                       z
            dk     sJ t          |                                j        t          d |                                D                       z
            dk     sJ d S )Nr  c              3   $   K   | ]}|j         V  d S r0   )r#  r   s     r;   	<genexpr>z-TestProcess.test_threads_2.<locals>.<genexpr>?  s$      (J(J(J(J(J(J(J(JrP   r   c              3   $   K   | ]}|j         V  d S r0   )r$  r   s     r;   r)  z-TestProcess.test_threads_2.<locals>.<genexpr>C  s$      *N*NQ1=*N*N*N*N*N*NrP   )r<   r
   r!  r2   r_   r%   r   r   r   r   sumr   rC   s     r;   test_threads_2zTestProcess.test_threads_24  s     	JJ		& J J Jk"HIIIJ "S(J(Jaiikk(J(J(J%J%JJKK    $s*N*N!))++*N*N*N'N'NNOO     s	   2 $Ac                 <   t          j                    }|                                d d         \  }}|                                }|dk    sJ |dk    sJ d gdz  }|                                d d         \  }}|                                }||k    sJ ||k    sJ ||k    sJ ~t          r8|                                }	|	j        |	j        k    sJ |	j        |	j        k    sJ |                                }	|	j	        D ]}
t          |	|
          dk    sJ d S )Nr   r   i` )r2   r3   memory_infomemory_percentr   rsswsetvmspagefiler   r   )r7   rD   rss1vms1percent1memarrrss2vms2percent2memr~   s              r;   test_memory_infozTestProcess.test_memory_infoG  sD   N ]]__RaR(
d##%%axxxxaxxxx '!]]__RaR(
d##%% d{{{{t||||("""" 	+--//C7ch&&&&7cl****mmooK 	+ 	+D3%%*****	+ 	+rP   c                    t          j                    }t          j                    j        }|                                }|j        D ]7}t          ||          }|dk    sJ |dk    rt          st          r/||k    sJ 8t          st          st          r|j        dk    sJ t          r|j        dk    sJ |j        dk    sJ d S d S )Nr   r2  )r2   r3   virtual_memorytotalmemory_full_infor   r   r   r   r   r   usspssswap)r7   rD   r?  r;  r~   r   s         r;   test_memory_full_infoz!TestProcess.test_memory_full_infof  s    N%''-  ""K 	" 	"DC&&EA::::#%E>>>>> 	 G 	 u 	 7a<<<< 	!7a<<<<8q====	! 	! =rP   c                    t          j                    }|                                }t          |          t          t	          |                    k    sJ |                    d          }|D ]}|j                            d          rt          r|j        dk    r1t          j        	                    |j                  sJ |j                    t          r	 t          j                            |j                  s3t          j                            |j                  sJ |j                    # t          $ rT t          s t          d          5 }|                                }d d d            n# 1 swxY w Y   |j         d|vr Y !w xY wdt          j                            |j                  vrU	 t          j        |j                  }t%          j        |j                  sJ |j                    # t*          $ r Y w xY w|D ][}|j        D ]Q}t/          ||          }	|dk    r|d	v r|	s
J |	            *t1          |	t2                    sJ |	d
k    s
J |	            R\d S )NF)grouped[pvclockz/proc/self/smapsz
 (deleted)64r   >   addrpermsr   )r2   r3   memory_mapsr   setr   r   r   r?   isabsr   existsislinkAssertionErrorr   r   r   basenamestatS_ISREGst_modeFileNotFoundErrorr   r   r   int)
r7   rD   mapsext_mapsntr   datastfnamer   s
             r;   test_memory_mapszTestProcess.test_memory_mapsv  s   N}}4yyCD		NN****===// 	= 	=Bw!!#&&  rw)++7==))2227222 =7>>"'22 bgnn7 7  w   &     "#566 (! vvxx( ( ( ( ( ( ( ( ( ( ( ( ( ( ('---T99 :9 RW--bg6666=))B  <
33<<RW<<<< )   D 7  		- 		-B - -E**F??--- ''%''''%eS11111 A:::u::::-		- 		-sI   AD33!FE5)F5E99F<E9=FF;G>>
HHc                     t          j                    }t                      5 }d fd|                                D             } |          |v sJ 	 d d d            d S # 1 swxY w Y   d S )Nc                 z    t           j                            t           j                            |                     S r0   )r?   r   r   normcaserD   s    r;   normpathz8TestProcess.test_memory_maps_lists_lib.<locals>.normpath  s(    w''(8(8(;(;<<<rP   c                 0    g | ]} |j                   S  )r   )r   r   rc  s     r;   r   z:TestProcess.test_memory_maps_lists_lib.<locals>.<listcomp>  s%    BBBQ((BBBrP   )r2   r3   r!   rL  )r7   rD   r   libpathsrc  s       @r;   test_memory_maps_lists_libz&TestProcess.test_memory_maps_lists_lib  s     N "" 	.d= = = CBBB!--//BBBH8D>>X-----	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   3A$$A(+A(c                 <   t          j                    }|                                 t          j        t
                    5  |                    d           d d d            n# 1 swxY w Y   t          st          st          r|                    d           d S d S )Nz?!?)memtyperA  )	r2   r3   r/  r%   rA   r   r   r   r   rC   s     r;   test_memory_percentzTestProcess.test_memory_percent  s    N	]:&& 	, 	,U+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,E 	,W 	,U+++++	, 	,s   A$$A(+A(c                 .   |                                  }|                                sJ |                                sJ |                                 |                                 |                                rJ |                                rJ d S r0   )r<   
is_runningrG   rH   rC   s     r;   test_is_runningzTestProcess.test_is_running  s    ||~~||~~		<<>>!!!<<>>!!!!!rP   c                 R   |                                  }|                                }	 |t          k    sJ n# t          $ r t          rVt          |          t          t                    k    r1t          j        j        } ||           |t                    k    sJ nht          j
        d          dt          j
        d          }	 |                    |d          t          j        |d          k    sJ n# t          $ r Y nw xY wY nw xY wt          |ddg          }|dk    sJ d S )Nr   .re    rb   zimport os; print('hey')hey)r<   exer   rQ  r   r   r?   r   ra  sysversion_inforeplacer)   )r7   rD   rr  ra  verouts         r;   test_exezTestProcess.test_exe  sE   eegg	*$$$$$ 	 	 	 3s88s:667+x}}(<(<<<<<< )!,DDs/?/BDD;;sB//:3Ec23N3NNNNNN%   D	& #t6788e||||||s4   8 BD
/C76D
7
DD
DD
	D
c                    t           ddg}|                     |          }t          r,|                                g k    rt	          j        d          t          st          st          r'|                                d         t           k    sJ d S t          r~t          rw|                                d         }|t           k    rRd
                    |                                dd                    d
                    |dd                    k    sJ d S d
                    |                                          d
                    |          k    sJ d S )Nrb   2import time; [time.sleep(0.1) for x in range(100)]OPENBSD: returned EBUSYr    re   )r   r<   r	   cmdliner%   r   r
   r   r   r   join)r7   r}  rD   pyexes       r;   test_cmdlinezTestProcess.test_cmdline  s5   @

 g&& 	9aiikkR''+7888  	>W 	> 	>99;;q>Z//////  		AJ&&88AIIKKO448M8MMMMMF88AIIKK((CHHW,=,=======rP   zbroken on PYPYc                    t           g}|                    dgdz             |                    ddg           |                     |          }t          rD	 |                                |k    sJ d S # t
          j        $ r t          j        d          w xY w|                                }t          r|g k    rt          j        d          ||k    sJ d S )Nz-v2   rb   rz  z#OPENBSD: process turned into zombier{  )
r   extendr<   r
   r}  r2   ZombieProcessr%   r   r	   )r7   r}  rD   r  s       r;   test_long_cmdlinezTestProcess.test_long_cmdline  s    ,v{###GH	
 	
 	
 g&& 	"Iyy{{g------' I I Ik"GHHHI ))++C =#))k";<<<'>>>>>>s   A2 2$Bc                 l   |                                  }|                                                                }t          j                            t          j                            t          j                                                            }|	                    |          sJ ||f            d S r0   )
r<   r~   lowerr?   r   rR  r   rs  
executabler   )r7   rD   r~   r  s       r;   	test_namezTestProcess.test_name  s    vvxx~~  !1!1#.!A!ABBHHJJ%%44t}44444rP   zunreliable on PYPYc                    t          |                     t          j        dz                      }|ddg}|                     |          }t
          r	 |                                t          j        	                    |          k    sJ d S # t          $ rn |                                t          j        k    rGt          j        	                    |                              |                                          sJ n Y d S w xY w|                                t          j        	                    |          k    sJ d S )Nr   )suffixrb   rz  )r#   r   stringdigitsr<   r
   r~   r?   r   rR  rQ  statusr2   STATUS_ZOMBIEr   )r7   r  r}  rD   s       r;   test_long_namezTestProcess.test_long_name  s+   dooV]Q5FoGGHH@

 g&& 	7vvxx27#3#3E#:#:::::::!   88::!5557++E22==affhhGGGGGG HGG 6688rw//66666666s   7B A4DDc                 D   t          j                    }|                                \  }}}|t          j                    k    sJ |t          j                    k    sJ t          t          d          r+t          j                    |                                k    sJ d S d S N	getresuid)r2   r3   uidsr?   getuidgeteuidhasattrr  r7   rD   real	effective_saveds        r;   	test_uidszTestProcess.test_uidsD      N"#&&((iry{{""""BJLL(((( 2{## 	.<>>QVVXX----	. 	.--rP   c                 D   t          j                    }|                                \  }}}|t          j                    k    sJ |t          j                    k    sJ t          t          d          r+t          j                    |                                k    sJ d S d S r  )r2   r3   gidsr?   getgidgetegidr  	getresgidr  s        r;   	test_gidszTestProcess.test_gidsQ  r  rP   c                    fd}t          j                    t          j        t                    5                      d           d d d            n# 1 swxY w Y                                   }|                     ||           t          rd }t           j        t           j	        t           j
        t           j        t           j        t           j        fD ]}|                     |          5  	                     |                                           }|t           j        t           j        t           j        hv r||k    s|
|}||k    sJ n||k    sJ n# t           j        $ r Y nw xY wd d d            n# 1 swxY w Y   d S 	 t!          t"          d          rHt#          j        t"          j        t#          j                                                              k    sJ                     d                                           dk    sJ t!          t"          d          rHt#          j        t"          j        t#          j                                                              k    sJ t*          s/                    d                                           dk    sJ d S d S # t           j        $ r Y d S w xY w)Nc                 `    	                      |            d S # t          j        $ r Y d S w xY wr0   )nicer2   r_   )r   rD   s    r;   r   z&TestProcess.test_nice.<locals>.cleanup_  s@    t&   s    --str)priogetpriorityre   r   )r2   r3   r%   rA   r   r  r   r   IDLE_PRIORITY_CLASSBELOW_NORMAL_PRIORITY_CLASSNORMAL_PRIORITY_CLASSABOVE_NORMAL_PRIORITY_CLASSHIGH_PRIORITY_CLASSREALTIME_PRIORITY_CLASSsubTestr_   r  r?   r  PRIO_PROCESSr@   r   )r7   r   r   highest_prior  new_priorD   s         @r;   	test_nicezTestProcess.test_nice^  s@   	 	 	 	 	 N]9%% 	 	FF5MMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	vvxx&&& 3	L*2,2*. 4 4 \\t\,, 4 44t $%6688
  ">"6":$  
  (4//<3G/3'/<'?'?'?'?#+t#3#3#3#3#3# ".   4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4<2}-- r	DD6688$ $ $ $ q			vvxx1}}}}2}-- r	DD6688$ $ $ $
  )FF1III6688q====) )(=&   s[   AAA/E<1EAE<E-*E<,E--E<<F 	F 	DJ. .K Kc                 t    t          j                    }|                                t           j        k    sJ d S r0   )r2   r3   r  STATUS_RUNNINGrC   s     r;   test_statuszTestProcess.test_status  s1    NxxzzV2222222rP   c                    |                                  }|                                }t          r|                    d          \  }}t	          j                    }|                    d          rt          j        d          ||k    sJ dt          j
        v r|t          j
        d         k    sJ d S d S |t	          j                    k    sJ d S )N\$zrunning as service account
USERDOMAIN)r<   usernamer   splitgetpassgetuserendswithr%   r   r?   environ)r7   rD   r  domaingetpass_users        r;   test_usernamezTestProcess.test_username  s    ::<< 	1'~~d33FH"?,,L$$S)) @ k">???|++++rz))L!99999 *)99w00000000rP   c                     |                                  }|                                t          j                    k    sJ d S r0   )r<   cwdr?   getcwdrC   s     r;   test_cwdzTestProcess.test_cwd  s8    uuww")++%%%%%%rP   c                 j    t           ddg}|                     |          t          fd           d S )Nrb   zFimport os, time; os.chdir('..'); [time.sleep(0.1) for x in range(100)]c                                                        t          j                            t          j                              k    S r0   )r  r?   r   dirnamer  rb  s   r;   <lambda>z(TestProcess.test_cwd_2.<locals>.<lambda>  s(    15577bgoobikk&B&BB rP   )r   r<   r    )r7   ri   rD   s     @r;   
test_cwd_2zTestProcess.test_cwd_2  sH    	
 c""BBBBCCCCCrP   c           	      D   t          j                    }|                                }|s
J |            |                     |j        |           t	          t
          d          r,|t          t          j        |j                            k    sJ t          |          t          t          |                    k    sJ t          t          t          t          j        d                                        }|D ]}|                    |g           |                                |gk    sJ t	          t
          d          r>|                                t          t          j        |j                            k    sJ t	          |d          r2|                                d         |                                k    sJ |                    g            t          r2|                                |j                                        k    sJ n|                                |k    sJ t	          t
          d          r>|                                t          t          j        |j                            k    sJ t#          j        t&                    5  |                    d           d d d            n# 1 swxY w Y   |                    |           |                    t          |                     |                    t)          |                     d S )Nsched_getaffinityTpercpunum_cpur   re   )r2   r3   cpu_affinityr   r  r?   listr  r4   r   rM  r   r   r  r   _proc_get_eligible_cpusr%   rA   r   r   )r7   rD   initialall_cpusns        r;   test_cpu_affinityzTestProcess.test_cpu_affinity  s   N..""0002*++ 	@d2#7#>#>??????7||s3w<<000000c&"4D"A"A"ABBCCDD 	: 	:ANNA3>>##s****r.// M~~''40DQU0K0K+L+LLLLLq)$$ :~~''*aiikk9999
 	
r 	0>>##qw'A'A'C'CCCCCC>>##x////2*++ 	I>>##tB,@,G,G'H'HHHHH]9%% 	 	NN1	 	 	 	 	 	 	 	 	 	 	 	 	 	 		w	s8}}%%%	uX'''''s   J<<K K c                    |                                  }t          t          j        d                    dz   g}t	          j        t                    5  |                    |           d d d            n# 1 swxY w Y   t	          j        t                    5  |                    t          dd                     d d d            n# 1 swxY w Y   t	          j        t          t          f          5  |                    ddg           d d d            n# 1 swxY w Y   t	          j        t                    5  |                    ddg           d d d            d S # 1 swxY w Y   d S )	NTr  
   i'  i*  r   1r}   )
r<   r   r2   r   r%   rA   r   r  r   r   )r7   rD   invalid_cpus      r;   test_cpu_affinity_errsz"TestProcess.test_cpu_affinity_errs  s8   6+488899B>?]:&& 	( 	(NN;'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(]:&& 	0 	0NN5..///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0]Iz233 	% 	%NNAs8$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%]:&& 	$ 	$NNAr7###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$sH   A66A:=A:$C

CC5DD D=E""E&)E&c                 $   t          j                    }|                                }|s
J |            |                     |j        |           t	          |          dk    r
|d d         }g }t          t	          |          dz             D ]4}|                    d t          j        ||          D                        5|D ]K}|                    |           t          |                                          t          |          k    sJ Ld S )N   re   c              3   8   K   | ]}|t          |          V  d S r0   )r  )r   subsets     r;   r)  zATestProcess.test_cpu_affinity_all_combinations.<locals>.<genexpr>  sB        V     rP   )
r2   r3   r  r   r   r   r  	itertoolscombinationssorted)r7   rD   r  combosr   combos         r;   "test_cpu_affinity_all_combinationsz.TestProcess.test_cpu_affinity_all_combinations  s,   N..""000 w<<"crclGs7||a'(( 	 	AMM  '4Wa@@        	= 	=ENN5!!!!..**++ve}}<<<<<	= 	=rP   zbroken on BSDc                    t          j                    |                                 }                                |vsJ t	          |d          5 }|                    d           |                                 t          fd                                           d D             }t          j	        
                    |          |v sJ t          rD ]}|j	        |k    r|j        dk    sJ d d d            n# 1 swxY w Y   D ]0}t          j	                            |j	                  s
J |            1d| d}|                     t          d|g          t!          d	          D ]:}d
                                 D             }||v r n8t#          j        d           ;t          j	        
                    |          |v sJ |D ]+}t          j	                            |          s
J |            ,d S )Nr   s   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxc                  h    t                                                    t                     k    S r0   )r   
open_files)filesrD   s   r;   r  z-TestProcess.test_open_files.<locals>.<lambda>  s"    s1<<>>22c%jj@ rP   c                 V    g | ]&}t           j                            |j                  'S re  r?   r   ra  r   s     r;   r   z/TestProcess.test_open_files.<locals>.<listcomp>  s*    AAAa))!&11AAArP   r  zimport time; f = open(r'z/', 'r'); [time.sleep(0.1) for x in range(100)];rb   r   c                 V    g | ]&}t           j                            |j                  'S re  r  r   s     r;   r   z/TestProcess.test_open_files.<locals>.<listcomp>-  s*    JJJa))!&11JJJrP   ru   )r2   r3   r   r  r   r   flushr    r?   r   ra  r   positionisfiler<   r   r   r   sleep)	r7   r  r   	filenamesfiler}  r   r  rD   s	          @@r;   test_open_fileszTestProcess.test_open_files  st   N""U""""&$ 	51GGK   GGIII@@@@@AAALLNNEAA5AAAI7##F++y8888 5! 5 5DyF**#}4444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5  	3 	3D7>>$),,22d2222v    	 z49::s 	9 	9AJJ1<<>>JJJI""Jt7##F++y8888 	. 	.D7>>$''------	. 	.s   B$DDDc                 8   t          j                    }t          j        j        }|                                 }t          |d          5 }|                                D ]C} ||j                   ||j                  k    s|j	        |
                                k    r n+D|                     d|                                           ||j                   ||j                  k    sJ t          r|j	        dk    sJ n|j	        |
                                k    sJ |                                d         }|d         |j        k    sJ |d         |j	        k    sJ |j        |                                vsJ 	 d d d            d S # 1 swxY w Y   d S )Nwzno file found; files=r}   r   re   )r2   r3   r?   r   ra  r   r   r  r~   fdfilenor   r   )r7   rD   ra  r  fileobjr  ntuples          r;   test_open_files_2zTestProcess.test_open_files_27  s    N7#""&# 	6' L LHTY''88GL+A+AAAw'.."2"222E 3 ii J J JKKK8DI&&((7<*@*@@@@@ 3w"}}}}}w'.."2"22222\\^^A&F!9++++!9	))))<q||~~55555'	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   	D8FFFc                 "   t          j                    }|                                 }|                                }t	          |d          }|                     |j                   |                                |dz   k    sJ t          j                    }|                     |j                   |                                |dz   k    sJ |                                 |                                 |                                |k    sJ d S )Nr  re   r   )r2   r3   r   num_fdsr   r   closesocket)r7   rD   r  startr  socks         r;   test_num_fdszTestProcess.test_num_fdsR  s    N""		FC  
###yy{{eai''''}
###yy{{eai''''



yy{{e######rP   z not reliable on OPENBSD & NETBSDc                 4   t          j                    }t          |                                          }t	          d          D ]@}t          j        d           t          |                                          }||k    r d S A|                     d          )Nr   g?z2num ctx switches still the same after 2 iterations)r2   r3   r+  num_ctx_switchesr   r   r  r   )r7   rD   beforer   afters        r;   test_num_ctx_switchesz!TestProcess.test_num_ctx_switchesa  s    
 NQ''))**q 	 	AJt**,,--Ev~~ iiLMMMrP   c                 *   t          j                    }t          t          d          r+|                                t          j                    k    sJ |                                 }|                                t          j                    k    sJ d S )Ngetppid)r2   r3   r  r?   ppidr  r<   r@   rC   s     r;   	test_ppidzTestProcess.test_ppido  sv    N2y!! 	,6688rz||++++vvxx29;;&&&&&&rP   c                    |                                  }|                                j        t          j                    k    sJ t          j                    d         }t          j        |                                          J d S r   )r<   parentr4   r?   r@   r2   pidsr3   )r7   rD   
lowest_pids      r;   test_parentzTestProcess.test_parentv  sl    xxzz~,,,,[]]1%
~j))0022:::::rP   c                     t          j                    }|                                 \  }}|                                |k    sJ |                                |k    sJ d S r0   )r2   r3   rv   r  r7   r  rw   rx   s       r;   test_parent_multizTestProcess.test_parent_multi}  sa    !! 4466z  ""e++++||~~''''''rP   c                 F   t          j                    }|                                sJ |                                 \  }}|                                d         |k    sJ |                                d         |k    sJ |                                d         |k    sJ d S r   )r2   r3   parentsrv   r  s       r;   test_parentszTestProcess.test_parents  s    !!~~ 4466z}}q!V++++!!##A&%////!!##A&&000000rP   c                    t          j                    }|                                rJ |                    d          rJ |                     d          }|                                }|                    d          }||fD ]T}t	          |          dk    sJ |d         j        |j        k    sJ |d                                         |j        k    sJ Ud S )NT	recursiver   )creationflagsre   )r2   r3   childrenr<   r   r4   r  )r7   r  rw   	children1	children2r  s         r;   test_childrenzTestProcess.test_children  s    !!??$$$$$??T?22222 !!!22OO%%	OOdO33	"I. 	4 	4Hx==A%%%%A;?ei////A;##%%33333	4 	4rP   c                 L   t          j                    }|                                 \  }}|                                |gk    sJ |                    d          ||gk    sJ |                                 |                                 |                    d          rJ d S )NTr  )r2   r3   rv   r  rR   rH   r  s       r;   test_children_recursivez#TestProcess.test_children_recursive  s     !! 4466z  UG++++..5*2EEEEE 	

??T?2222222rP   c                 J   t          j        t                    }t          j                    D ]:}	 ||                                xx         dz  cc<   &# t          j        $ r Y 7w xY wt          |                                d           d         }t          r|dk    rt          j        d          t          j        |          }	 |                    d          }t          |          t          t          |                    k    sJ d S # t          j        $ r Y d S w xY w)Nre   c                     | d         S )Nre   re  )r   s    r;   r  z6TestProcess.test_children_duplicates.<locals>.<lambda>  s
    qt rP   )keyr   zPID 0Tr  )collectionsdefaultdictrW  r2   process_iterr  Errormaxitemsr   r%   r   r3   r  r   rM  r_   )r7   tablerD   r4   cs        r;   test_children_duplicatesz$TestProcess.test_children_duplicates  s-   ',,$&& 	 	Aaffhh1$<    %++--^^444Q7 	'SAXX+g&&&N3	)

T
**A q66SQ[[(((((( " 	 	 	DD	s#   "AA%$A%D D"!D"c                 H   t          j                    }|                                 \  }}|                    d          }t	          |          dk    sJ |d         |k    sJ |d         |k    sJ |                                }|d         |k    sJ |d         |k    sJ d S )NTr  r   r   re   )r2   r3   rv   r  r   r  )r7   r  rw   rx   r  r  s         r;   test_parents_and_childrenz%TestProcess.test_parents_and_children  s    !! 4466z??T?228}}!!!!{e####{j(((($$&&qzU""""qzV######rP   c                 Z   |                                  }|                                 t          d          D ]:}|                                t          j        k    r nt          j        d           ;|                                 |                                t          j        k    sJ d S )Nr   ru   )	r<   rq   r   r  r2   STATUS_STOPPEDr   r  rr   )r7   rD   r   s      r;   test_suspend_resumezTestProcess.test_suspend_resume  s    			s 	 	AxxzzV222Jt	


xxzzV2222222rP   c                    t          j        t                    5  t          j        d           d d d            n# 1 swxY w Y   t          j        t
                    5  t          j        d           d d d            d S # 1 swxY w Y   d S )Nr  r}   )r%   rA   r   r2   r3   r   )r7   s    r;   test_invalid_pidzTestProcess.test_invalid_pid  s    ]9%% 	  	 N3	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 ]:&& 	 	N2	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   ;??BBBc                 V   t          j                    }|                    ddg          }t          |                                          ddgk    sJ t          j        t          t          j                                        }|                    dgd          }t          |d         t                    s|d         dk    sJ t          j
        ddt           j        	          5  |                    d
gd          d
dik    sJ 	 d d d            n# 1 swxY w Y   t          j
        ddt          j        |j        d          	          5  t          j        t           j                  5  |                    d
g           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j
        ddt          j        |j        d          	          5  |                    d
gd          d
dik    sJ 	 d d d            n# 1 swxY w Y   t          j
        ddt"          	          5  |                                }d
t          |                                          vsJ t          j        t"                    5  |                    d
g           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        t$                    5  |                    d           d d d            n# 1 swxY w Y   t          j        t&                    5  |                    dg           d d d            n# 1 swxY w Y   t          j        t&                    5  |                    ddg           d d d            d S # 1 swxY w Y   d S )Nrr  r~   )attrsnet_connectionsfoo)r8  ad_valuezpsutil.Process.niceT)creater[   r  re   bar)r2   r3   as_dictr  keysminr  r   r  r   r\   r_   r5   r4   r%   rA   r  NotImplementedErrorr   r   )r7   rD   ds      r;   test_as_dictzTestProcess.test_as_dict  s   NIIUFOI,,affhhE6?2222N3v{}}--..II./%I@@!-.55 	1&'50000 Z!$F<O
 
 
 	H 	H 99F8a988VQKGGGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H Z!,QUF;;
 
 
 	* 	*
 v344 * *			)))* * * * * * * * * * * * * * *	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* Z!,QUF;;
 
 
 	P 	P
 99F8e9<<OOOOO	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P Z!$<O
 
 
 	* 	* 		Aaffhh////233 * *			)))* * * * * * * * * * * * * * *	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* ]9%% 	 	IIf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]:&& 	 	IIug	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]:&& 	& 	&IIuen%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s   )!DDDF+0FF+F	F+F	F++F/2F/%!HHH:AKJ1%K1J5	5K8J5	9KKK,LLL2MMM9NN"%N"c                 
   t          j                    }t          j        d          5 }|                                5  |                                 |                                 d d d            n# 1 swxY w Y   |j        dk    sJ 	 d d d            n# 1 swxY w Y   t          j        d          5 }|                                 |                                 d d d            n# 1 swxY w Y   |j        dk    sJ d S )N$psutil._psplatform.Process.cpu_timesre   r   r2   r3   r   r\   oneshotr   
call_countr7   rD   r   s      r;   test_oneshotzTestProcess.test_oneshot  s   NZ>?? 	%1                 <1$$$$$		% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% Z>?? 	1KKMMMKKMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 |q      sF   B)A2&B2A6	6B9A6	:BBB6)C++C/2C/c           	      $   t          j                    }t          j        d          5 }t          j        d          5 }|                                5  |                                 |                                 |                                5  |                                 |                                 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |j        dk    sJ |j        dk    sJ 	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        d          5 }|                                 |                                 d d d            n# 1 swxY w Y   |j        dk    sJ d S )NrE  z(psutil._psplatform.Process.oneshot_enterre   r   rF  )r7   rD   m1m2r   s        r;   test_oneshot_twicezTestProcess.test_oneshot_twice  s    NZ>?? 		*2FGG *2YY[[ & &KKMMMKKMMM & && & & & & & & & & & & & & & && & & & & & & & & & & & & & & }))))})))))* * * * * * * * * * * * * * *		* 		* 		* 		* 		* 		* 		* 		* 		* 		* 		* 		* 		* 		* 		* Z>?? 	1KKMMMKKMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 |q      s   D$D=C)C	8CCCCCDCD"C#DD$D	D$D	D$$D(+D()E88E<?E<c                    |                                  \  }}|                                }|                                }||k    sJ |                                5  |                                |k    sJ |                                |k    sJ 	 d d d            n# 1 swxY w Y   |                                5  |                                |k    sJ |                                |k    sJ 	 d d d            d S # 1 swxY w Y   d S r0   )rv   r  rG  )r7   p1p2p1_ppidp2_ppids        r;   test_oneshot_cachezTestProcess.test_oneshot_cache.  s    ))++B''))''))'!!!!ZZ\\ 	( 	(7799''''7799'''''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( ZZ\\ 	( 	(7799''''7799'''''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s$   5BB"%B"=5D  DDc                 ^     fd}                                                                                                    t          rt	          fd                                           t                    }|                    |j                  D ]\  }} |||           d S )Nc                     	  |             }t           r|dv rd S                     | d|d          # t          j        $ r  t          j        $ r Y d S t          j        $ r t          r|dv rY d S  w xY w)N>   rr  r~   z didn't raise NSP and returned z instead>   r!  r  )r   r   r2   r  r5   r_   r
   )funfun_namer  r7   s      r;   assert_raises_nspzFTestProcess.test_halfway_terminated_process.<locals>.assert_raises_nspE  s    cee  x?::FiiLLSLLL   '   '   &    x+EEEFFs   
5 A4A42A4c                  8     j         t          j                    vS r0   )r4   r2   r  rb  s   r;   r  z=TestProcess.test_halfway_terminated_process.<locals>.<lambda>\  s    quFKMM9 rP   )	r<   rR   rH   r   r    rL   r$   iterall)r7   rY  nsrW  r~   rD   s   `    @r;   test_halfway_terminated_processz+TestProcess.test_halfway_terminated_process=  s    	 	 	 	 	& 		 	;9999:::q!!!q!! 	) 	)ICc4((((	) 	)rP   c                 ^    |                                  \  }}|                     |           d S r0   )spawn_zombieassertProcessZombie)r7   _parentzombies      r;   test_zombie_processzTestProcess.test_zombie_processc  s1    ++--  (((((rP   c                     t          j                    }t          j        dt          j        d                    5 }|                                sJ |j        sJ 	 d d d            d S # 1 swxY w Y   d S )Nzpsutil.Processr   rZ   )r2   r3   r   r\   r  rl  r   rI  s      r;   $test_zombie_process_is_running_w_excz0TestProcess.test_zombie_process_is_running_w_exch  s     NZ&*>q*A*A
 
 
 	<<>>!!!8OOOO		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s    A**A.1A.c                 
   t          j                    }t          j        dt          j        d                    5 }|                                t           j        k    sJ |j        sJ 	 d d d            d S # 1 swxY w Y   d S )Nz!psutil._psplatform.Process.statusr   rZ   )r2   r3   r   r\   r  r  r  r   rI  s      r;    test_zombie_process_status_w_excz,TestProcess.test_zombie_process_status_w_excs  s     NZ/,Q//
 
 
 	 88::!555558OOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   .A88A<?A<c                 (   |                                  }t          j        |j                  }|j        |                                dz   f|_        t          t          j                               |j        t          j        v sJ |	                                rJ t          j                            t          j        dd          5  t          j        t!          j                              5 }t          t          j                               d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d|j         |                                v sJ |j        t          j        vsJ |t          j        |j                  k    sJ d}t'          |          }|                    |j        |j        z   d          D ]u\  }}|                     |          5  t1          j        t          j        |	          5   |             d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   vd
t7          |          v sJ d
t9          |          v sJ t1          j        t          j        |	          5  |                                 d d d            n# 1 swxY w Y   t1          j        t          j        |	          5  |                                 d d d            n# 1 swxY w Y   t1          j        t          j        |	          5  |                                 d d d            n# 1 swxY w Y   t1          j        t          j        |	          5  |                                  d d d            d S # 1 swxY w Y   d S )Nr   PSUTIL_DEBUGTz+refreshing Process instance for reused PID z4process no longer exists and its PID has been reusedF)clear_cache)r~   r   zterminated + PID reused)!r1   r2   r3   r4   r   _identr  r)  _pmaprl  r   r\   object_common
contextlibredirect_stderrioStringIOgetvaluer$   r[  setterskillersr  r%   rA   r5   r  reprr  r  r  r  )r7   subprD   r   msgr]  rW  r~   s           r;   test_reused_pidzTestProcess.test_reused_pid  s   ""$$N48$$E1==??S01V ""###u$$$$<<>>!!! Zv~~tDD 	, 	,+BKMM:: ,aV(**+++, , , , , , , , , , , , , , ,	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, B!%AAzz||    uFL((((FN48,,,,,,Dq!!bj!8eLL 	 	IC4((  ]6#7sCCC  CEEE                             )CFF2222(DGG3333]6/s;;; 	 	FFHHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]6/s;;; 	 	HHJJJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]6/s;;; 	 	IIKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]6/s;;; 	 	JJLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   &D1-!DD1D	D1!D	"D11D58D5 !H/HH/HH/H H//H3	6H3	J""J&)J&K..K25K2L::L>L>%NNNc                 x   dt          j                    vrt          j        t           j                  5  t          j        d           d d d            n# 1 swxY w Y   t          j        d          rJ t          j        d                                          dk    sJ d S t          j        d          }t          rt           j	        nt          }t          j        |          5  |                                 d d d            n# 1 swxY w Y   t          j        |          5  |                                 d d d            n# 1 swxY w Y   t          j        |          5  |                                 d d d            n# 1 swxY w Y   t          j        |          5  |                                 d d d            n# 1 swxY w Y   t          j        |          5  |                                 d d d            n# 1 swxY w Y   t          j        |          5  |                    t"          j                   d d d            n# 1 swxY w Y   t'          |          }|                    |j        |j        z             D ]u\  }}	  |            }|dv r|j        dk    sJ "|dk    r&t          rdnd}|                                |k    sJ N|dk    r|s
J |            a# t           j	        $ r Y rw xY wt2          s-dt          j                    v sJ t          j        d          sJ d S d S )Nr   re   >   r  r  r  zNT AUTHORITY\SYSTEMrootr~   )r2   r  r%   rA   r5   r3   
pid_existsr  r   r_   r   rH   rR   rq   rr   rG   rU   rI   rJ   r$   r[  gettersru  r  r  r
   )r7   rD   r  r]  rW  r~   r  r   s           r;   
test_pid_0zTestProcess.test_pid_0  s   FKMM!!v344 " "q!!!" " " " " " " " " " " " " " " (+++++>!$$))++q0000FN1%,<f!!*]3 	 	FFHHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]3 	 	KKMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]3 	 	IIKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]3 	 	HHJJJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]3 	 	FFHHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]3 	* 	*MM&.)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* q!!bj!899 	& 	&IC&cee +++8q=====Z''5<H11&D::<<4/////V^^%%%%% &     	(%%%%$Q'''''	( 	(''s   AAA&DDD&EEE&FFF&GGG&HHH& III
K//L Lc                     d }d | _         t          j                    } ||                                          } |t          j                                                  }t          st          r
||k    sJ d S d S d S )Nc                     g d}t           r|                    g d           |D ]}|                     |d            d |                                 D             S )N)PLATHOMEPYTEST_CURRENT_TESTPYTEST_VERSION)__CF_USER_TEXT_ENCODINGVERSIONER_PYTHON_PREFER_32_BITVERSIONER_PYTHON_VERSIONr  c                     i | ]X\  }}|                     d d                               dd          |                     d d                               dd          YS )rp  
)ru  )r   kvs      r;   
<dictcomp>z@TestProcess.test_environ.<locals>.clean_dict.<locals>.<dictcomp>  sp        Aq 		$##++D"55qyy"8 8'$##  rP   )r   r  popr,  )rB  excluder~   s      r;   
clean_dictz,TestProcess.test_environ.<locals>.clean_dict  s    OOOG             " "dD!!!!  GGII	   rP   )maxDiffr2   r3   r  r?   copyr   r   )r7   r  rD   d1d2s        r;   test_environzTestProcess.test_environ  s    	 	 	$ NZ		$$Z
))** 	~ 	8888	 	 	 	8rP   z<macOS 11+ can't get another process environment, issue #2084z(sometimes fails on `assert is_running()`c                    t          j        d          }t          |                                 |          }|                     |gt
          j        t
          j                  }t          j        |j	                  }t          |j	                   |                                sJ |j                                        dk    sJ t          r3t          r,	 |                                }n*# t          j        $ r Y d S w xY w|                                }|dddk    sJ |                                 |j        dk    sJ d S )	Na  
            #include <unistd.h>
            #include <fcntl.h>

            char * const argv[] = {"cat", 0};
            char * const envp[] = {"A=1", "X", "C=3", 0};

            int main(void) {
                // Close stderr on exec so parent can wait for the
                // execve to finish.
                if (fcntl(2, F_SETFD, FD_CLOEXEC) != 0)
                    return 0;
                return execve("/bin/cat", argv, envp);
            }
            )c_code)stdinrd   rP   r  3)ACr   )textwrapdedentr"   r   r1   rg   rh   r2   r3   r4   r,   rl  rd   r   r   r   r  r_   communicate
returncode)r7   rN   cexer:   rD   envs         r;   test_weird_environzTestProcess.test_weird_environ  sS         DOO--d;;;##F*/*/ $ 
 
 N59%%QU||~~|  ""c)))) 	Z 	iikk&    
 ))++CCc******1$$$$$$s   C+ +C>=C>N)h__name__
__module____qualname____doc__r<   rE   rO   rS   rW   r%   markskipifr   r`   rj   r	   rs   r{   r   r   r   r   r   r   r   r   r   r   r   r+   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r   r&  r(   r*   r   r,  r<  rD  r   r^  rg  rj  rm  rx  r  r   r  r  r  r  r  r  r  r  r  r  r   r  r  r  r   r  r  r  r
   r
  r  r  r  r  r!  r#  r/  r1  r4  r6  rC  rJ  rN  rT  r^  rd  rf  rh  rz  r  r   r  r   r  re  rP   r;   r.   r.   I   s
       ))    " " "" " "	" 	" 	" [E	+66
# 
# 76
#" " "6 ['899. . :9.2/ / /.  " " "(	' 	' 	'  
L 
L 
L> > > [,,_EE8 8 FE8L L L$ [E	,77	' 	' 87	' [00IIU+++$ $ ,+ JI$L [J??[E	,77) ) 87 @?)V [J??[?   - -  @?-4 [J??$ $ @?$. [J??
6 
6 @?
6 [J??A A @?A$ [J??A A @?A [J??	4 	4 @?	4& & &" [GN;;# # <;#
 [K@@5 5 A@5& 5)))[K@@
 
 A@ *) 
  + + +<! ! !  [O+ODD.- .- ED.-` [O+ODD	. 	. ED	., , ," " "  6> > >6 [%566" " 76"*5 5 5 [%9::7 7 ;:7Z [E	,77
. 
. 87
. [E	,77
. 
. 87
.@ @ @D3 3 31 1 1"& & &
D 
D 
D [,,_EE$( $( FE$(L [,,_EE
$ 
$ FE
$ [,,_EE= = FE=, [O44#. #. 54#.L [O446 6 5464 [E	,77$ $ 87$ U+++[6"D   N N  ,+N' ' '; ; ;( ( ( 1 1 14 4 43 3 3) ) )($ $ $3 3 3  2& 2& 2&h! ! !! ! !(( ( ($) $) $)L [E	,77) ) 87) [E	,77  87 [E	,77	 	 87	' ' 'R,( ,( ,(\ [K@@  A@4 [K@@[E	,77[M    [A   %% %% 	  87 A@%% %% %%rP   r.   c                   @    e Zd ZdZed             Zd Zd Zd Zd Z	dS )	TestPopenzTests for psutil.Popen class.c                 "    t                       d S r0   r&   )clss    r;   tearDownClasszTestPopen.tearDownClass*  s    rP   c                 l   t           ddg}t          j        |t          j        t          j        t
                    5 }|                                 |                                 |j         t          |          sJ t          j        t                    5  |j         d d d            n# 1 swxY w Y   |                                 d d d            n# 1 swxY w Y   t          r(|                    d          t"          j         k    sJ d S |                    d          t"          j        k    sJ d S )Nrb   3import time; [time.sleep(0.1) for x in range(100)];stdoutrd   r  rf   )r   r2   Popenrg   rh   r   r~   r   r  r   r%   rA   rB   r:  rR   r   rH   rI   rJ   r7   ri   procs      r;   	test_misczTestPopen.test_misc.  s   
 A

 \??	
 
 
 	
 IIKKKNNJJt99~..                NN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  	299Q<<FN?22222299Q<<6>111111s6   ACB*C*B.	.C1B.	2CCCc                 R   t          j        t          dgt          j        t          j        t          j        t
                    5 }|                                 d d d            n# 1 swxY w Y   |j        j        sJ |j	        j        sJ |j
        j        sJ |j        dk    sJ d S )Nz-V)r  rd   r  r  r   )r2   r  r   rg   rh   r   r  r  closedrd   r  r  )r7   r  s     r;   test_ctx_managerzTestPopen.test_ctx_managerI  s    \??/
 
 
 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 {!!!!{!!!!z    !######s   A%%A),A)c                 2   t           ddg}t          j        |t          j        t          j        t
                    5 }|                                 |                                 t          j	        t          j
                  5  |                                 d d d            n# 1 swxY w Y   t          j	        t          j
                  5  |                                 d d d            n# 1 swxY w Y   t          j	        t          j
                  5  |                    t          j                   d d d            n# 1 swxY w Y   t          rt          j	        t          j
                  5  |                    t          j                   d d d            n# 1 swxY w Y   t          j	        t          j
                  5  |                    t          j                   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S Nrb   r  r  )r   r2   r  rg   rh   r   rR   rH   r%   rA   r5   rG   rU   rI   rJ   r   CTRL_C_EVENTCTRL_BREAK_EVENTr  s      r;   test_kill_terminatezTestPopen.test_kill_terminateW  s/   
 A

 \??	
 
 
 	>
 NNIIKKKv344 ! !   ! ! ! ! ! ! ! ! ! ! ! ! ! ! !v344  		              v344 1 1  0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 >]6#788 : :$$V%8999: : : : : : : : : : : : : : :]6#788 > >$$V%<===> > > > > > > > > > > > > > >#	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s   AHB$H$B(	(H+B(	,!HC."H.C2	2H5C2	6!H E7HE	H
E	(H3 FHF#	#H&F#	'!H G4(H4G8	8H;G8	<HHHc                 n   t           ddg}t          j        |t          j        t          j        t
                    5 }|                                 |                                 t          j	        t                    5  |j         d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r  )r   r2   r  rg   rh   r   rR   rH   r%   rA   rB   r:  r  s      r;   test__getattribute__zTestPopen.test__getattribute__t  s(   A

 \??	
 
 
 		
 NNIIKKK~..                		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		s6   AB*>BB*B	B*B	B**B.1B.N)
r  r  r  r  classmethodr  r  r  r  r  re  rP   r;   r  r  '  so        ''  [2 2 26$ $ $> > >:    rP   r  )>r  r'  rp  r  r  rr  r  r?   rI   r  rS  r  rg   rs  r  r   unittestr   r2   r   r   r   r   r	   r
   r   r   r   psutil._commonr   psutil.testsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r'   r(   r)   r*   r+   r,   r.   r  re  rP   r;   <module>r     s   & %           				     				         



                                                                $ $ $ $ $ $ # # # # # # ' ' ' ' ' ' ' ' ' ' ' ' ) ) ) ) ) ) $ $ $ $ $ $ # # # # # # ( ( ( ( ( ( ) ) ) ) ) ) - - - - - - # # # # # # $ $ $ $ $ $ % % % % % %       # # # # # # ' ' ' ' ' ' ' ' ' ' ' ' # # # # # # # # # # # # , , , , , , % % % % % % & & & & & & * * * * * *       & & & & & & ) ) ) ) ) )       . . . . . . 0 0 0 0 0 0 % % % % % %V% V% V% V% V%. V% V% V%|.\ \ \ \ \ \ \ \ \ \rP   