
    ɧd                     .   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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 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; dd-l m<Z<  G d. d/e/          Z=er! ej>                    dk    r G d0 d1e=          Z? G d2 d3e/          Z@eAd4k    rdd5lBmCZC  eCeD           dS dS )6Tests for psutil.Process class.    N)AIX)BSD)LINUX)MACOS)NETBSD)OPENBSD)OSX)POSIX)SUNOS)WINDOWS)	open_text)PY3)FileNotFoundError)long)super)APPVEYOR)
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)PYPY)
PYTHON_EXE)PsutilTestCase)
ThreadTask)
call_until)copyload_shared_lib)
create_exe)mock)process_namespacereap_children)retry_on_failure)sh)skip_on_access_denied)skip_on_not_implemented)unittest)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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-e.           e	j
        e* d          d&                                     Z/ e,            d'             Z0d( Z1 e	j
        e2 d          d)             Z3 e	j
        e2 d          d*             Z4d+ Z5d, Z6d- Z7d. Z8 e	j
        e9d/          d0             Z:d1 Z; e	j
        e9d2          d3             Z< e	j
        e=d4           e	j
        e>d5           e	j
        e9d/          d6                                     Z? e	j
        e d          d7             Z@ e	j
        e d          d8             ZAd9 ZBd: ZCd; ZDd< ZEd= ZF e	j
        eG d          d>             ZH e	j
        eG d          d?             ZI e	j
        eG d          d@             ZJ e	j
        eKdA           e	j
        eLdB          dC                         ZM e	j
        eKdA           e	j
        eLdB          dD                         ZN e	j
        e d          dE             ZO ee           e	j
        ePpeQdF          dG                         ZRdH ZSdI ZTdJ ZUdK ZV e,            dL             ZWdM ZXdN ZYdO ZZdP Z[dQ Z\dR Z]dS Z^dT Z_dU Z`dV ZadW Zb e	j
        e d          dX             Zc e	j
        e d          dY             Zd e	j
        e d          dZ             Zed[ Zfd\ Zg e	j
        eh d          d]             Zi e	j
        eh d           e	j
        e d          d^                         Zjd_S )`TestProcessr   c                 N     | j         |i |}t          j        |j                  S N)spawn_testprocpsutilProcesspid)selfargskwargssprocs       9lib/python3.11/site-packages/psutil/tests/test_process.pyspawn_psproczTestProcess.spawn_psprocM   s+    ##T4V44~ei(((    c                     t          j                    }|                     |j        t	          j                               |                     t                    5  d|_        d d d            d S # 1 swxY w Y   d S )N!   )r5   r6   assertEqualr7   osgetpidassertRaisesAttributeErrorr8   ps     r<   test_pidzTestProcess.test_pidS   s    N	,,,~.. 	 	AE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A//A36A3c                 :   |                                  }|                                 |                                }t          r!|                     |t
          j                   n!|                     |t
          j                    |                     |           d S r3   )	r=   killwaitr   rA   signalSIGTERMSIGKILLassertProcessGoner8   rG   codes      r<   	test_killzTestProcess.test_killY   s    	vvxx 	4T6>2222TFN?333q!!!!!r>   c                 :   |                                  }|                                 |                                }t          r!|                     |t
          j                   n!|                     |t
          j                    |                     |           d S r3   )r=   	terminaterK   r   rA   rL   rM   rO   rP   s      r<   test_terminatezTestProcess.test_terminatec   s    	vvxx 	4T6>2222TFN?333q!!!!!r>   c                 R   t           rt          j        nt          j        }|                                 }|                    |           |                                }t          r|                     ||           n|                     ||            | 	                    |           d S r3   )
r   rL   rN   rM   r=   send_signalrK   r   rA   rO   )r8   sigrG   rQ   s       r<   test_send_signalzTestProcess.test_send_signalm   s     %9fnn6>	cvvxx 	)T3''''TC4(((q!!!!!r>   z	not POSIXc                     t           j        }|                                 }t          j        dt          t          j        d                    5  |                     t          j
        |j        |           d d d            n# 1 swxY w Y   |                                 }t          j        dt          t          j        d                    5  |                     t          j        |j        |           d d d            d S # 1 swxY w Y   d S )Nzpsutil.os.kill side_effect)rL   rM   r=   r&   patchOSErrorerrnoESRCHrD   r5   NoSuchProcessrW   EPERMAccessDenied)r8   rX   rG   s      r<   test_send_signal_mockedz#TestProcess.test_send_signal_mockedx   s   nZ($+EK$<$<> > > 	H 	Hf2AM3GGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H Z($+EK$<$<> > > 	G 	Gf11=#FFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs$   'BB	B'DD
Dc                    t           ddg}|                     |          }|                                }|                     |d           |                     |           t           ddg}|                     |t
          j                  }|                                }|                     |d           |                     |           t           ddg}|                     |          }|                                }|                     |d           |                     |           t           dd	g}|                     |          }|                                }|                     |d           |                     |           d S )
N-cpassr   z1 / 0)stderr   zimport sys; sys.exit(5);   zimport os; os._exit(5);)r    r=   rK   rA   rO   
subprocessPIPE)r8   cmdrG   rQ   s       r<   test_wait_exitedzTestProcess.test_wait_exited   sk    4(c""vvxxq!!!q!!!4)c*/::vvxxq!!!q!!!4!;<c""vvxxq!!!q!!!4!:;c""vvxxq!!!q!!!!!r>   c                 @   |                                  }t          r|                    t          j                   |                     t          j        |j        d           |                    t          j	                   |                     t          j        |j        d           |                    t          j
                   |                     |                                t          j
                    |                     |                                t          j
                    d S |                                 |                     t          j        |j        d           |                                 |                     t          j        |j        d           |                                 |                     |                                t          j
                   |                     |                                t          j
                   d S )NMbP?)timeout)r=   r   rW   rL   SIGSTOPrD   r5   TimeoutExpiredrK   SIGCONTrM   rA   suspendresumerT   rF   s     r<   test_wait_stoppedzTestProcess.test_wait_stopped   s    	7 MM&.)))f3QVUKKKMM&.)))f3QVUKKKMM&.)))QVVXX777QVVXX77777IIKKKf3QVUKKKHHJJJf3QVUKKKKKMMMQVVXXv~666QVVXXv~66666r>   c                 l   |                                  \  }}|                     t          j        |j        d           |                     t          j        |j        d           |                                 |                                 |                                }|                                }t          r9|                     |t          j	                    |                     |d            d S |                     |t          j	                   |                     |t          j	                   d S )N{Gz?)
spawn_children_pairrD   r5   rt   rK   rT   r   rA   rL   rM   )r8   child
grandchild	child_retgrandchild_rets        r<   test_wait_non_childrenz"TestProcess.test_wait_non_children   s
    !4466z&/TBBB&/$GGG 	JJLL	#** 	8Y888 ^T22222Y777Y77777r>   c                 0   |                                  }|                                 |                     t          j        |j        d           |                     t          j        |j        d           |                     t          |j        d           d S )Nrz   r   )r=   namerD   r5   rt   rK   
ValueErrorrF   s     r<   test_wait_timeoutzTestProcess.test_wait_timeout   sz    	&/>>>&/;;;*afb11111r>   c                 r   |                                  }|                     t          j        |j        d           |                                 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                    n | 
                    |t          j                   |                     |           d S )Nr   rr   )r=   rD   r5   rt   rK   rJ   timer   failr   rA   rL   rN   rM   rO   )r8   rG   stop_atrQ   s       r<   test_wait_timeout_nonblockingz)TestProcess.test_wait_timeout_nonblocking   s   &/;;;	)++.ikkG# 	'vvayy(   	 ikkG# 	' ))I&&& 	3TFN?3333T6>222q!!!!!s   B B*)B*c                    t          j                    }|                    d           |                    d           t          d          D ]I}|                    d           }|                     |t
                     |                     |d           J|                     t                    5  |                    d           d d d            d S # 1 swxY w Y   d S )Nrq   )intervald           r   )	r5   r6   cpu_percentrangeassertIsInstancefloatassertGreaterEqualrD   r   )r8   rG   xpercents       r<   test_cpu_percentzTestProcess.test_cpu_percent   s   N	u%%%	u%%%s 	2 	2AmmTm22G!!'5111##GS1111z** 	' 	'MM2M&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   3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^   r5   r6   r   called)r8   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        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)r5   r6   	cpu_timesusersystemchildren_userchildren_systemr   iowait_fieldsr   strftime	localtimegetattr)r8   timesr   s      r<   test_cpu_timeszTestProcess.test_cpu_times   s      **,,
S @elS&8@@5@@@#s*22U222%,44u444 	.<3&-----M 	L 	LDM*dnWUD5I5I&J&JKKKK	L 	Lr>   c                    t          j                                                    d d         \  }}t          j                    d d         \  }}t          ||g          t          ||g          z
  dk    r|                     d|d|           t          ||g          t          ||g          z
  dk    r|                     d|d|           d S d S )N   皙?
expected: 	, found: )r5   r6   r   rB   r   maxminr   )r8   	user_timekernel_timeutimektimes        r<   test_cpu_times_2zTestProcess.test_cpu_times_2   s    !'!1!1!;!;!=!=bqb!A	;xzz"1"~u
 E"##c9e*<&=&==D 	FIII555))DEEEe$%%[%,@(A(AASH 	HIII555++FGGGGG	H 	Hr>   znot supportedc                 f   t          j                    }|                                }|                     |d           t          j                    dk    r|                     |d           |                     |                                t          t          j                                         d S Nr   rj   )r5   r6   cpu_numr   	cpu_countrA   assertInr   )r8   rG   nums      r<   test_cpu_numzTestProcess.test_cpu_num  s    NiikkQ'''" 	%S!$$$aiikk5)9););#<#<=====r>   c                 Z   |                                  }t          j                    }|                                }t          ||z
            }|dk    r|                     d|d|d|           t          j        dt          j        |                                                     d S )Nr   r   r   z, difference: z%Y %m %d %H:%M:%S)r=   r   create_timeabsr   r   r   )r8   rG   nowr   
differences        r<   test_create_timezTestProcess.test_create_time  s    ikkmmoo
 s*++
> 	8IIIkkk::7 8 8 8 	)4>!--//+J+JKKKKKr>   z
POSIX onlyc                     t          j                                                    }|Dt          j                            t          d                    }|                     ||           d S d S )Ntty)r5   r6   terminalrB   pathrealpathr+   rA   )r8   r   r   s      r<   test_terminalzTestProcess.test_terminal&  sd    >##,,.. 	,'""2e99--CXs+++++	, 	,r>   )only_ifc                 R   t          j                    }|                                }t          t          d          5 }|                                 d d d            n# 1 swxY w Y   |                                }t          st          s|                     |j	        |j	                   | 
                    |j        |j                   t          r@|                     |j        |j                   | 
                    |j        |j                   n@|                     |j        |j                   |                     |j        |j                   |                                }t          |                                 d          5 }t&          r'|                    t+          ddz  d                     n|                    ddz             d d d            n# 1 swxY w Y   |                                }|                     |j        |j                   |                     |j        |j                   |                     |j	        |j	                   |                     |j        |j                   t          r@|                     |j        |j                   |                     |j        |j                   t-          t/          |                    D ]H}t          r|dk    r|                     ||         d           |                     ||         d           Id S )Nrbwbr   i@B asciir   r   )r5   r6   io_countersopenr    readr   r   assertGreater
read_countrA   write_countr   
read_charswrite_charsr   
read_byteswrite_bytes
get_testfnr   writebytesr   len)r8   rG   io1fio2is         r<   test_io_counterszTestProcess.test_io_counters-  s5    Nmmoo*d## 	qFFHHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	mmoo 	F3 	Fs~s~>>>S_co>>> C""3>3>BBB  #/BBB##CNCNCCC##COS_EEE mmoo$//##T** 	'a 'cGmW556666g&&&		' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'
 mmooAAAAAA?????? 	Ds@@@##CNCNCCC s3xx 	/ 	/A qAv ##CFA...##CFA....	/ 	/s$   AA"%A"	AGG #G z
linux onlyc                    t          j                    }t          s8|                     |                                d         t           j                   |                     t           j        d           |                     t           j        d           |                     t           j        d           |                     t           j        d           |                                }	 |                    t           j                   |                     t          |                                          t           j        df           | 
                    t                    5  |                    t           j        d           d d d            n# 1 swxY w Y   |                    t           j                   |                     t          |                                          t           j        df           |                    t           j        d           |                     t          |                                          t           j        df           | 
                    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          d|j        t           j        d           |                     t          d|j        t           j        d           |                     t          d	|j        d           |\  }}|t           j        k    rd}|                    ||           d S # |\  }}|t           j        k    rd}|                    ||           w xY w)
Nr   rj   r         value   zioclass accepts no valuez$'ioclass' argument must be specified)r5   r6   r   rA   ioniceIOPRIO_CLASS_NONEIOPRIO_CLASS_RTIOPRIO_CLASS_BEIOPRIO_CLASS_IDLEtuplerD   r   rd   assertRaisesRegex)r8   rG   initioclassr   s        r<   test_ionice_linuxzTestProcess.test_ionice_linuxX  s    N 	FQXXZZ]F,DEEE11555/333/33311555xxzz	%HHV-...U188::..1I10MNNN"":.. < <1;;;< < < < < < < < < < < < < < < HHV+,,,U188::..1G0KLLLHHV+1H555U188::..1G0KLLL"":.. : :/q999: : : : : : : : : : : : : : :/q9999&    ""6&2A7 7 7 ""6&2A7 7 7 ""B # # # # "NGU&22 HHWe$$$$$ "NGU&22 HHWe$$$$s{   (A:N ""FN FN FCN 7"J%N %J))N ,J)-N 1!K N K%"N $K%%B N /Oz!not supported on this win versionc                    t          j                    }t          s2|                     |                                t           j                   |                                }	 |                    t           j                   |                     |                                t           j                   |                    t           j                   |                     |                                t           j                   	 |                    t           j                   |                     |                                t           j                   n# t           j	        $ r Y nw xY w| 
                    t          d|j        t           j        d           | 
                    t          d|j        t           j        dz              |                    |           d S # |                    |           w xY w)Nz&value argument not accepted on Windowsrj   r   zis not a valid priority)r5   r6   r   rA   r   IOPRIO_NORMALIOPRIO_VERYLOW
IOPRIO_LOWIOPRIO_HIGHrd   r   	TypeErrorr   )r8   rG   r   s      r<   test_ionice_winzTestProcess.test_ionice_win  s    N 	?QXXZZ)=>>>xxzz	HHV*+++QXXZZ)>???HHV&'''QXXZZ):;;;A+,,,   V-?@@@@ &   
 ""C&.a # 9 9 9 ""5&,q02 2 2 HHTNNNNNAHHTNNNNs2   "B"G  E $3G  E)&G  (E))A G   G7c                    dd l }t          j        t          j                              }d t          t                    D             }|s
J |            |D ]}t          t          |          }|                     |d           |t          |          v ri|                     |t          ||                     t          rk|                     |
                    |          |                    |                     |
                    |          }|                     t          |          d           |                     |d         d           |                     |d         d           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Br>   r   r   rj   )resourcer5   r6   rB   rC   dirr   r   rA   r   rlimit	getrlimitr   )r8   r   rG   namesr   r   rets          r<   test_rlimit_getzTestProcess.test_rlimit_get  s^   N29;;''BBCKKBBBe 	4 	4DFD))E##E1---s8}}$ 4  $(?(?@@@    %(2D2DU2K2KLLLLhhuoo  S1---''A333''A3333	4 	4r>   c                 R   |                                  }|                    t          j        d           |                     |                    t          j                  d           t
          re|                     t          d          5  t          j        	                    d                              d           d d d            n# 1 swxY w Y   | 
                    t                    5  |                    t          j        d           d d d            d S # 1 swxY w Y   d S )N)rk   rk   zcan't use prlimitr   )rk   rk   rk   )r=   r  r5   RLIMIT_NOFILErA   r   r   r   _psplatformr6   rD   rF   s     r<   test_rlimit_setzTestProcess.test_rlimit_set  sy   	%v...&"677@@@  	8''
4GHH 8 8"**1--44Q7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8z** 	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$   
3C		CC.!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                    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   | 	                    t          r|j        j        n|j        d         t          j                   |                    t           j        ||f           | 	                    |                    t           j                  ||f           d S # |                    t           j        ||f           | 	                    |                    t           j                  ||f           w xY w)N   r   s   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXs  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXr   )r5   r6   r   r  RLIMIT_FSIZEr   r   rD   IOErrorrA   r   	exceptionr`   EFBIG)r8   rG   testfnsofthardr   excs          r<   test_rlimitzTestProcess.test_rlimit  sw   N""XXf122
d	JHHV(4,777fd## %q$$$% % % % % % % % % % % % % % % ""7++ )s&$'' )1GGK((() ) ) ) ) ) ) ) ) ) ) ) ) ) )) ) ) ) ) ) ) ) ) ) ) ) ) ) ) CMS]00S]1=M"[* * * HHV(4,777QXXf&9::T4LIIIII HHV(4,777QXXf&9::T4LIIIIsz   2F0 =BF0 B##F0 &B#'F0 DC7+D7C;	;D>C;	?DF0 DF0 DAF0 0AH	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           d S # |                    t           j        ||f           |                     |                    t           j                  ||f           w xY w)Nr  r   s   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX)	r5   r6   r  r  RLIM_INFINITYr   r   r   rA   )r8   rG   r  r  r   s        r<   test_rlimit_infinityz TestProcess.test_rlimit_infinity  s    NXXf122
d	JHHV(4,777HHV(6+?*FGGGdoo''.. %!$$$% % % % % % % % % % % % % % % HHV(4,777QXXf&9::T4LIIIII HHV(4,777QXXf&9::T4LIIIIs1   A0D- 'C	=D- 	CD- CD- -AFc                     t          j                    }|                    t           j                  \  }}|                     t           j        |           |                    t           j        ||f           d S r3   )r5   r6   r  r  rA   r  )r8   rG   r  r  s       r<   test_rlimit_infinity_valuez&TestProcess.test_rlimit_infinity_value  sc     NXXf122
d-t444	$tTl33333r>   c                    t          j                    }t          r=	 |                                }n;# t           j        $ r t          j        d          w xY w|                                }t                      5  |                                }|                     ||dz              d d d            d S # 1 swxY w Y   d S )N$on OpenBSD this requires root accessrj   )	r5   r6   r	   num_threadsrd   r.   SkipTestr"   rA   )r8   rG   step1step2s       r<   test_num_threadszTestProcess.test_num_threads  s    N 	$P& P P P'(NOOOP MMOOE\\ 	/ 	/MMOOEUEAI...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   1 $A:.B55B9<B9zWINDOWS onlyc                 |    t          j                    }|                     |                                d           d S Nr   )r5   r6   r   num_handlesrF   s     r<   test_num_handleszTestProcess.test_num_handles  s5     N1==??A.....r>   c                    t          j                    }t          r=	 |                                }n;# t           j        $ r t          j        d          w xY w|                                }t                      5  |                                }|                     t          |          t          |          dz              |d         }|                     |j
        |d                    |                     |j        |d                    |                     |j        |d                    d d d            d S # 1 swxY w Y   d S )Nr  rj   r   r   )r5   r6   r	   threadsrd   r.   r  r"   rA   r   idr   system_time)r8   rG   r  r  athreads        r<   test_threadszTestProcess.test_threads  so   N 	 P		& P P P'(NOOOP IIKKE\\ 	> 	>IIKKESZZUa888AhGWZ444W.
;;;W0'!*===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s   1 $A:B3D::D>D>c                    |                                  }t          r=	 |                                 n'# t          j        $ r t          j        d          w xY w|                     |                                j	        t          d |                                D                       d           |                     |                                j        t          d |                                D                       d           d S )Nr  c                     g | ]	}|j         
S  )r   r   s     r<   r   z.TestProcess.test_threads_2.<locals>.<listcomp>,  s    222222r>   r   )deltac                     g | ]	}|j         
S r-  )r(  r   s     r<   r   z.TestProcess.test_threads_2.<locals>.<listcomp>/  s    4441444r>   )r=   r	   r&  r5   rd   r.   r  assertAlmostEqualr   r   sumr   rF   s     r<   test_threads_2zTestProcess.test_threads_2  s     	<<		& < < <':< < << 	KKMM22aiikk222333 	 	@ 	@ 	@ 	KKMM 44		44455S 	 	B 	B 	B 	B 	Bs	   2 $Ac                    t          j                    }|                                d d         \  }}|                                }|                     |d           |                     |d           d gdz  }|                                d d         \  }}|                                }|                     ||           |                     ||           |                     ||           ~t          rT|                                }	|                     |	j        |	j	                   |                     |	j
        |	j                   |                                }	|	j        D ]&}
|                     t          |	|
          d           'd S )Nr   r   i` )r5   r6   memory_infomemory_percentr   r   r   rA   rsswsetvmspagefiler   r   )r8   rG   rss1vms1percent1memarrrss2vms2percent2memr   s              r<   test_memory_infozTestProcess.test_memory_info1  s|   N ]]__RaR(
d##%%4###4### '!]]__RaR(
d##%% 	4&&&d+++8X... 	4--//CSWch///SWcl333mmooK 	; 	;D##GC$6$6::::	; 	;r>   c                 *   t          j                    }t          j                    j        }|                                }|j        D ]\}t          ||          }|                     |d||f           |dk    rt          st          rA| 
                    |||||f           ]t          st          st          r|                     |j        d           t          r8|                     |j        d           |                     |j        d           d S d S )Nr   )msgr8  )r5   r6   virtual_memorytotalmemory_full_infor   r   r   r
   r   assertLessEqualr   r   usspssswap)r8   rG   rF  rA  r   r   s         r<   test_memory_full_infoz!TestProcess.test_memory_full_infoP  s*   N%''-  ""K 	I 	IDC&&E##E14-#@@@u}     D%3G HHHH 	0G 	0u 	0##CGQ/// 	1##CGQ///##CHa00000	1 	1r>   c                    t          j                    }|                                }d |D             }|                     t	          |          t	          t          |                               |                    d          }|D ]}|j                            d          sot          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   d|j        z  |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 ]f}|j        D ]\}	t/          ||	          }
|	dk    r|	d	v r|
s
J |
            *|                     |
t2          t4          f           |
d
k    s
J |
            ]gd S )Nc                     g | ]}|S r-  r-  r   s     r<   r   z0TestProcess.test_memory_maps.<locals>.<listcomp>d  s    !!!q!!!r>   F)grouped[z/proc/self/smapsz%s (deleted)64r   )addrpermsr   )r5   r6   memory_mapsrA   r   setr   r   rB   isabsr   existsislinkAssertionErrorr   r   r   basenamestatS_ISREGst_moder   r   r   r   intr   )r8   rG   mapspathsext_mapsntr   datastfnamer   s              r<   test_memory_mapszTestProcess.test_memory_maps`  s   N}}!!D!!!USU__555===// 	E 	EB7%%c** Ew}}RW--66rw666 E&!w~~bg66 =GNN2733= =57W= = =) & & &$ &! "++=!>!> 0!'(vvxx0 0 0 0 0 0 0 0 0 0 0 0 0 0 0-7tC & %& && 27#3#3BG#<#<< EE!#!1!1B $(<
#;#;DDRWDDDD  1 ! ! ! D!  		- 		-B - -E**F? -// - ''%''''))%#t=== A:,,u,,,,-		- 		-sI   "AD::!FE<0F<F  FF FFH
HHc                     t          j                    }t                      5 }d fd|                                D             }|                      |          |           d d d            d S # 1 swxY w Y   d S )Nc                 z    t           j                            t           j                            |                     S r3   )rB   r   r   normcase)rG   s    r<   normpathz8TestProcess.test_memory_maps_lists_lib.<locals>.normpath  s(    w''(8(8(;(;<<<r>   c                 0    g | ]} |j                   S r-  )r   )r   r   rj  s     r<   r   z:TestProcess.test_memory_maps_lists_lib.<locals>.<listcomp>  s5     2 2 2 !(( 2 2 2r>   )r5   r6   r$   rT  r   )r8   rG   r   libpathsrj  s       @r<   test_memory_maps_lists_libz&TestProcess.test_memory_maps_lists_lib  s     N "" 	4d= = =2 2 2 2!"2 2 2HMM((4..(333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   AA33A7:A7c                     t          j                    }|                                 |                     t          |j        d           t
          st          st          r|                    d           d S d S )Nz?!?)memtyperI  )r5   r6   r5  rD   r   r   r   r   rF   s     r<   test_memory_percentzTestProcess.test_memory_percent  s|    N	*a&6FFF 	,E 	,W 	,U+++++	, 	,r>   c                 .   |                                  }|                                sJ |                                sJ |                                 |                                 |                                rJ |                                rJ d S r3   )r=   
is_runningrJ   rK   rF   s     r<   test_is_runningzTestProcess.test_is_running  s    ||~~||~~		<<>>!!!<<>>!!!!!r>   c                    |                                  }|                                }	 |                     |t                     n# t          $ r t
          rdt          |          t          t                    k    r?t          j        j	        }|                      ||           |t                               nvt          j        d         dt          j        d         }	 |                     |                    |d          t          j        |d                     n# t          $ r Y nw xY wY nw xY wt          |ddg          }|                     |d           d S )Nr   .rj   r[   rg   zimport os; print('hey')hey)r=   exerA   r    rY  r   r   rB   r   ri  sysversion_inforeplacer+   )r8   rG   rw  ri  verouts         r<   test_exezTestProcess.test_exe  sn   eegg	S*---- 	 	 	 3s88s:6 7+  #0D0DEEEE "%!1!!4!4!4c6Fq6I6IJ$$S[[b%9%9%/%7R%@%@B B B B%   D!	( #t6788e$$$$$s6   A BD4#=D! D4!
D.+D4-D..D43D4c                    t           ddg}|                     |          }t          st          st          r5|                     |                                d         t                      d S t          rt          r|                                d         }|t           k    r`|                     d	                    |                                dd                    d	                    |dd                               d S |                     d	                    |                                          d	                    |                     d S )Nrg   zimport time; time.sleep(60)r    rj   )
r    r=   r   r	   r   rA   cmdliner   r   join)r8   r  rG   pyexes       r<   test_cmdlinezTestProcess.test_cmdline  s    t%BCg&&  		GW 		G 		GQYY[[^Z88888  		AJ& $$SXXaiikk!""o%>%>%(XXgabbk%:%:< < <FSXXaiikk22CHHW4E4EFFFFFr>   zbroken on PYPYc                     |                                  }t          |           |gdgdz  z   }|                     |          }|                     |                                |           d S )N
0123456789   )r   r%   r=   rA   r  )r8   r  r  rG   s       r<   test_long_cmdlinezTestProcess.test_long_cmdline  si    ""6(|nr12g&&g.....r>   c                 x   |                      t                    }|                                                                }t          j                            t          j                            t          j	                                                            }|
                    |          sJ ||f            d S r3   )r=   r    r   lowerrB   r   rZ  r   rx  
executabler   )r8   rG   r   r  s       r<   	test_namezTestProcess.test_name  s    j))vvxx~~  !1!1#.!A!ABBHHJJ%%44t}44444r>   zunreliable on PYPYc                    |                      d          }t          |           |                     |          }|                     |                                t
          j                            |                     d S )N01234567890123456789suffix)r   r%   r=   rA   r   rB   r   rZ  )r8   r  rG   s      r<   test_long_namezTestProcess.test_long_name  sk    (8996f%%27#3#3F#;#;<<<<<r>   zbroken on SUNOSzbroken on AIXc                 *   |                      d          }t          |           |ddddddg}|                     |          }|                     |                                |           |                     |                                t          j                            |                     |                     t          j        	                    |
                                          t          j        	                    |                     d S )Nz	foo bar )r  rg   z9import time; [time.sleep(0.01) for x in range(3000)];arg1arg2r[   arg3)r   r%   r=   rA   r  r   rB   r   rZ  ri  rw  )r8   
funky_pathr  rG   s       r<   test_prog_w_funky_namez"TestProcess.test_prog_w_funky_name  s     __K_88
:t!2vr3 g&&g...27#3#3J#?#?@@@))!%%''22))*55	7 	7 	7 	7 	7r>   c                    t          j                    }|                                \  }}}|                     |t	          j                               |                     |t	          j                               t          t          d          r;|                     t	          j                    |                                           d S d S N	getresuid)	r5   r6   uidsrA   rB   getuidgeteuidhasattrr  r8   rG   real	effectivesaveds        r<   	test_uidszTestProcess.test_uids       N!"iry{{+++BJLL111 2{## 	7R\^^QVVXX66666	7 	7r>   c                    t          j                    }|                                \  }}}|                     |t	          j                               |                     |t	          j                               t          t          d          r;|                     t	          j                    |                                           d S d S r  )	r5   r6   gidsrA   rB   getgidgetegidr  	getresgidr  s        r<   	test_gidszTestProcess.test_gids  r  r>   c                    t          j                    }|                     t          |j        d           |                                }	 t
          rt           j        t           j        t           j        t           j	        t           j
        t           j        fD ]}|                     |          5  	 |                    |           |                     |                                |           n# t           j        $ r Y nw xY wd d d            n# 1 swxY w Y   nn	 t          t           d          rV|                     t!          j        t           j        t!          j                              |                                           |                    d           |                     |                                d           t          t           d          rV|                     t!          j        t           j        t!          j                              |                                           t(          s=|                    d           |                     |                                d           n# t           j        $ r Y nw xY w	 |                    |           d S # t           j        $ r Y d S w xY w# 	 |                    |           w # t           j        $ r Y w w xY wxY w)Nstr)priogetpriorityrj   r   )r5   r6   rD   r   nicer   NORMAL_PRIORITY_CLASSIDLE_PRIORITY_CLASSBELOW_NORMAL_PRIORITY_CLASSREALTIME_PRIORITY_CLASSHIGH_PRIORITY_CLASSABOVE_NORMAL_PRIORITY_CLASSsubTestrA   rd   r  rB   r  PRIO_PROCESSrC   r   )r8   rG   r   r  s       r<   	test_nicezTestProcess.test_nice  s   N)QVU333vvxx&	  #9#7#?#;#7#?A = =D 400 = ==FF4LLL !,,QVVXXt<<<<  &2 ! ! ! D!= = = = = = = = = = = = = = ==r=11 &((N2?BIKKHHFFHH& & & FF1III$$QVVXXq111r=11 &((N2?BIKKHHFFHH& & &
 ! 6q			((1555*   Dt&   t&   s   
A#J8 -D/C-)D-C?<D>C??DJ8 D	J8 D	J8 EI5 4J8 5JJ8 JJ8 J" "J54J58K%:KK%K"K%!K""K%c                     t          j                    }|                     |                                t           j                   d S r3   )r5   r6   rA   statusSTATUS_RUNNINGrF   s     r<   test_statuszTestProcess.test_statusH  s6    NV%:;;;;;r>   c                    |                                  }|                                }t          rw|                    d          \  }}|                     |t          j                               dt          j        v r(|                     |t          j        d                    d S d S |                     |t          j                               d S )N\
USERDOMAIN)	r=   usernamer   splitrA   getpassgetuserrB   environ)r8   rG   r  domains       r<   test_usernamezTestProcess.test_usernameL  s    ::<< 	:'~~d33FHXw'8'8999rz) C  L)ABBBBBC C Xw'8'899999r>   c                     |                                  }|                     |                                t          j                               d S r3   )r=   rA   cwdrB   getcwdrF   s     r<   test_cwdzTestProcess.test_cwdW  s=    ")++.....r>   c                 n    t           ddg}|                     |          }t          |j        d           d S )Nrg   z/import os, time; os.chdir('..'); time.sleep(60)z#ret == os.path.dirname(os.getcwd()))r    r=   r#   r  )r8   rn   rG   s      r<   
test_cwd_2zTestProcess.test_cwd_2[  s>    4@Bc""15?@@@@@r>   c           	         t          j                    }|                                }|s
J |            |                     |j        |           t	          t
          d          r:|                     |t          t          j        |j	                                       |                     t          |          t          t          |                               t          t          t          t          j        d                                        }|D ]}|                    |g           |                     |                                |g           t	          t
          d          rL|                     |                                t          t          j        |j	                                       t	          |d          r@|                     |                                d         |                                           |                    g            t          r@|                     |                                |j                                                   n(|                     |                                |           t	          t
          d          rL|                     |                                t          t          j        |j	                                       |                     t&          |j        d           |                    |           |                    t          |                     |                    t)          |                     d S )Nsched_getaffinityTpercpunum_cpur   rj   )r5   r6   cpu_affinity
addCleanupr  rB   rA   listr  r7   r   rU  r   r   r  r   _proc_get_eligible_cpusrD   r   r   )r8   rG   initialall_cpusns        r<   test_cpu_affinityzTestProcess.test_cpu_affinitya  s   N..""0002*++ 	IWd2+?+F+F&G&GHHHWs3w<<'8'8999c&"4D"A"A"ABBCCDD 	C 	CANNA3Q^^--s333r.// D  !1!1!%b&:15&A&A!B!BD D D q)$$ C  !1!1!!4aiikkBBB
 	
r 	9Q^^--qw/I/I/K/KLLLLQ^^--x8882*++ 	@Q^^--!""6qu"="=>>@ @ @ 	)Q^Q777	w	s8}}%%%	uX'''''r>   c                    |                                  }t          t          j        d                    dz   g}|                     t
          |j        |           |                     t
          |j        t          dd                     |                     t          |j        ddg           |                     t
          |j        ddg           d S )	NTr  
   i'  i*  r   1r   )	r=   r   r5   r   rD   r   r  r   r   )r8   rG   invalid_cpus      r<   test_cpu_affinity_errsz"TestProcess.test_cpu_affinity_errs  s    6+488899B>?*ankBBB*aneE56I6IJJJ)Q^aX>>>*anq"g>>>>>r>   c                 V   t          j                    }|                                }|s
J |            |                     |j        |           t	          |          dk    r
|d d         }g }t          dt	          |          dz             D ]>}t          j        ||          D ]&}|r"|                    t          |                     '?|D ]Y}|                    |           | 
                    t          |                                          t          |                     Zd S )N   r   rj   )r5   r6   r  r  r   r   	itertoolscombinationsappendr  rA   sorted)r8   rG   r  combosr   subsetcombos          r<   "test_cpu_affinity_all_combinationsz.TestProcess.test_cpu_affinity_all_combinations  s7   N..""000 w<<" 	#crclGq#g,,*++ 	0 	0A#0!<< 0 0 0MM$v,,///0  	F 	FENN5!!!VANN$4$455ve}}EEEE	F 	Fr>   zbroken on BSDzunreliable on APPVEYORc                 v   t          j                    }|                                 }|                                }|                     ||           t          |d          5 }|                    d           |                                 t          |j        dt          |          z            }d |D             }| 
                    t          j                            |          |           t          r+|D ](}|j        |k    r|                     |j        d           )d d d            n# 1 swxY w Y   |D ]0}t          j                            |j                  s
J |            1d|z  }|                     t&          d|g          }t)          d          D ]:}d	 |                                D             }||v r nHt+          j        d
           ;| 
                    t          j                            |          |           |D ]+}t          j                            |          s
J |            ,d S )Nr   s   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzlen(ret) != %ic                 V    g | ]&}t           j                            |j                  'S r-  rB   r   ri  r   s     r<   r   z/TestProcess.test_open_files.<locals>.<listcomp>  s*    AAAa))!&11AAAr>   r  z2import time; f = open(r'%s', 'r'); time.sleep(60);rg   r   c                 V    g | ]&}t           j                            |j                  'S r-  r  r   s     r<   r   z/TestProcess.test_open_files.<locals>.<listcomp>  s*    JJJa))!&11JJJr>   rz   )r5   r6   r   
open_filesassertNotInr   r   flushr#   r   r   rB   r   ri  r   rA   positionisfiler=   r    r   r   sleep)	r8   rG   r  filesr   	filenamesfiler  r   s	            r<   test_open_fileszTestProcess.test_open_files  si    N""'''&$ 
	>1GGK   GGIIIq|-=E

-JKKEAA5AAAIMM"'**622I>>> >! > >DyF* >((===
	> 
	> 
	> 
	> 
	> 
	> 
	> 
	> 
	> 
	> 
	> 
	> 
	> 
	> 
	>  	3 	3D7>>$),,22d2222 GOz49::s 	? 	?AJJ1<<>>JJJI" JsOOOOMM"'**622I>>> 	. 	.D7>>$''------	. 	.s   "C D..D25D2c                    t          j                    }t          j        j        }|                                 }t          |d          5 }|                                D ]C} ||j                   ||j                  k    s|j	        |
                                k    r n8D|                     dt          |                                          z             |                      ||j                   ||j                             t          r|                     |j	        d           n-|                     |j	        |
                                           |                                d         }|                     |d         |j                   |                     |d         |j	                   |                     |j        |                                           d d d            d S # 1 swxY w Y   d S )Nwzno file found; files=%sr   r   rj   )r5   r6   rB   r   ri  r   r   r  r   fdfilenor   reprrA   r   r  )r8   rG   ri  r  fileobjr  ntuples          r<   test_open_files_2zTestProcess.test_open_files_2  s   
 N7#""&# 	;' L L8DI&&((7<*@*@@ 7>>#3#33E 		3d1<<>>6J6JJKKKXXdi00((7<2H2HIII <  "----  '..*:*:;;;\\^^A&FVAY444VAY	222W\1<<>>:::#	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   	FG11G58G5c                 v   t          j                    }|                                 }|                                }t	          |d          }|                     |j                   |                     |                                |dz              t          j                    }|                     |j                   |                     |                                |dz              |                                 |                                 |                     |                                |           d S )Nr  rj   r   )	r5   r6   r   num_fdsr   r  closerA   socket)r8   rG   r  startr  socks         r<   test_num_fdszTestProcess.test_num_fds  s    N""		FC  
###eai000}
###eai000



e,,,,,r>   z not reliable on OPENBSD & NETBSDc                    t          j                    }t          |                                          }t	          d          D ],}t          |                                          }||k    r d S -|                     d           d S )Ni  z7num ctx switches still the same after 50.000 iterations)r5   r6   r1  num_ctx_switchesr   r   )r8   rG   beforer   afters        r<   test_num_ctx_switchesz!TestProcess.test_num_ctx_switches  s     NQ''))**v 	 	A**,,--Ev~ 		KLLLLLr>   c                 t   t          j                    }t          t          d          r9|                     |                                t          j                               |                                 }|                     |                                t          j                               t          rd S d S )Ngetppid)
r5   r6   r  rB   rA   ppidr  r=   rC   r   rF   s     r<   	test_ppidzTestProcess.test_ppid  s    N2y!! 	5QVVXXrz||44429;;/// 	 F		 	r>   c                 N   |                                  }|                     |                                j        t	          j                               t          j                    d         }|                     t          j	        |                                                     d S r"  )
r=   rA   parentr7   rB   rC   r5   pidsassertIsNoner6   )r8   rG   
lowest_pids      r<   test_parentzTestProcess.test_parent  sy    555[]]1%
&.44;;==>>>>>r>   c                     t          j                    }|                                 \  }}|                     |                                |           |                     |                                |           d S r3   )r5   r6   r{   rA   r  r8   r  r|   r}   s       r<   test_parent_multizTestProcess.test_parent_multi  sk    !! 4466z**,,e44400000r>   c                     |                                  }t          j        dt          j        dd                    5  |                     |                                           d d d            d S # 1 swxY w Y   d S )Npsutil.Processr   foor\   )r=   r&   r^   r5   rb   r  r  rF   s     r<   test_parent_disappearedz#TestProcess.test_parent_disappeared  s    Z($*$8E$B$BD D D 	* 	*ahhjj)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   (A33A7:A7c                    t          j                    }|                                sJ |                                 \  }}|                     |                                d         |           |                     |                                d         |           |                     |                                d         |           d S r   )r5   r6   parentsr{   rA   r  s       r<   test_parentszTestProcess.test_parents!  s    !!~~ 4466z+V444++--a0%888++--a0&99999r>   c                 V   t          j                    }|                     |                                g            |                     |                    d          g            |                     d          }|                                }|                    d          }||fD ]~}|                     t          |          d           |                     |d         j        |j                   |                     |d                                         |j                   d S )NT	recursiver   )creationflagsrj   )r5   r6   rA   childrenr=   r   r7   r  )r8   r  r|   	children1	children2r"  s         r<   test_childrenzTestProcess.test_children*  s   !!**B///488"=== !!!22OO%%	OOdO33	"I. 	= 	=HS]]A...Xa[_ei888Xa[--//<<<<	= 	=r>   c                    t          j                    }|                                 \  }}|                     |                                |g           |                     |                    d          ||g           |                                 |                                 |                     |                    d          g            d S )NTr  )r5   r6   r{   rA   r"  rT   rK   r  s       r<   test_children_recursivez#TestProcess.test_children_recursive9  s     !! 4466z**UG4444885*:MNNN 	

488"=====r>   c                 t   t          j        t                    }t          j                    D ]:}	 ||                                xx         dz  cc<   &# t          j        $ r Y 7w xY wt          |                                d           d         d         }t          r|dk    r| 
                    d          t          j        |          }	 |                    d          }|                     t          |          t          t          |                               d S # t          j        $ r Y d S w xY w)	Nrj   c                     | d         S )Nrj   r-  )r   s    r<   <lambda>z6TestProcess.test_children_duplicates.<locals>.<lambda>O  s
    !A$ r>   )keyr   r   zPID 0Tr  )collectionsdefaultdictr^  r5   process_iterr  Errorr  itemsr   skipTestr6   r"  rA   r   rU  rd   )r8   tablerG   r7   cs        r<   test_children_duplicatesz$TestProcess.test_children_duplicatesF  s<   ',,$&& 	 	Aaffhh1$<    U[[]]777;A> 	)SAX 	)--(((N3	2

T
**A SVVSQ[[11111 " 	 	 	DD	s#   "AA%$A%D$ $D76D7c                    t          j                    }|                                 \  }}|                    d          }|                     t          |          d           |                     |d         |           |                     |d         |           |                                }|                     |d         |           |                     |d         |           d S )NTr  r   r   rj   )r5   r6   r{   r"  rA   r   r  )r8   r  r|   r}   r"  r  s         r<   test_parents_and_childrenz%TestProcess.test_parents_and_childrenZ  s    !! 4466z??T?22X***!e,,,!j111$$&&U+++V,,,,,r>   c                 v   |                                  }|                                 t          d          D ]:}|                                t          j        k    r nt          j        d           ;|                                 | 	                    |                                t          j                   d S )Nr   rz   )
r=   rv   r   r  r5   STATUS_STOPPEDr   r  rw   assertNotEqual)r8   rG   r   s      r<   test_suspend_resumezTestProcess.test_suspend_resumeg  s    			s 	 	AxxzzV22 Jt	


AHHJJ(=>>>>>r>   c                     |                      t          t          j        d           |                      t          t          j        d           d S )Nr  r   )rD   r   r5   r6   r   r8   s    r<   test_invalid_pidzTestProcess.test_invalid_pidq  s<    )V^S999*fnb99999r>   c                    t          j                    }|                    ddg          }|                     t	          |                                          ddg           t          j        t          t          j                                        }|                    dgd          }t          |d         t                    s|                     |d         d           t          j        ddt           j        	          5  |                     |                    d
gd          d
di           d d d            n# 1 swxY w Y   t          j        ddt          j        |j        d          	          5  |                     t           j        |j        d
g           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           d d d            n# 1 swxY w Y   t          j        ddt"          	          5  |                                }|                     d
t          |                                                     |                     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&                    5  |                    d           d d d            n# 1 swxY w Y   |                     t(                    5  |                    dg           d d d            n# 1 swxY w Y   |                     t(                    5  |                    ddg           d d d            d S # 1 swxY w Y   d S )Nrw  r   )attrsconnectionsr  )r?  ad_valuezpsutil.Process.niceT)creater]   r  rj   bar)r5   r6   as_dictrA   r  keysr   r  
isinstancer  r&   r^   rd   rb   r7   rD   ZombieProcessNotImplementedErrorr  r   r   )r8   rG   ds      r<   test_as_dictzTestProcess.test_as_dictu  s   NIIUFOI,,))E6?;;;N3v{}}--..II]OeI<<!M*D11 	6Q}-u555 Z-d$*$79 9 9 	D 	D		1	55{D D D	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D Z-d$*$8$G$GI I I 	A 	A$aix  A A A	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A Z-d$*$8$G$GI I I 	L 	L		5	99FE?L L L	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L Z-d$79 9 9 	* 	*		AVT!&&((^^444""#677 * *			)))* * * * * * * * * * * * * * *	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* y)) 	 	IIf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	z** 	 	IIug	 	 	 	 	 	 	 	 	 	 	 	 	 	 	z** 	& 	&IIuen%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s   /E  EE:)F//F36F3)/H$$H(+H(A$K*/KK*K	K*K	K**K.1K.L11L58L5M99M= M=OO
Oc                 @   t          j                    }t          j        d          5 }|                                5  |                                 |                                 d d d            n# 1 swxY w Y   |                     |j        d           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           d S )N$psutil._psplatform.Process.cpu_timesrj   r   r5   r6   r&   r^   oneshotr   rA   
call_countr8   rG   r   s      r<   test_oneshotzTestProcess.test_oneshot  s   NZ>?? 	.1                 Q\1---		. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. Z>?? 	1KKMMMKKMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	q)))))sF   B$)A2&B$2A6	6B$9A6	:B$$B(+B()C88C<?C<c           	      v   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           |                     |j        d           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           d S )NrL  z(psutil._psplatform.Process.oneshot_enterrj   r   rM  )r8   rG   m1m2r   s        r<   test_oneshot_twicezTestProcess.test_oneshot_twice  s    NZ>?? 		32FGG 32YY[[ & &KKMMMKKMMM & && & & & & & & & & & & & & & && & & & & & & & & & & & & & &   222  2223 3 3 3 3 3 3 3 3 3 3 3 3 3 3		3 		3 		3 		3 		3 		3 		3 		3 		3 		3 		3 		3 		3 		3 		3 Z>?? 	1KKMMMKKMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	q)))))s   D?D(=C)C	8CCCCCD(CD("C#9D(D?(D,	,D?/D,	0D??EE)FFFc                    |                                  \  }}|                                }|                                }|                     ||           |                                5  |                     |                                |           |                     |                                |           d d d            n# 1 swxY w Y   |                                5  |                     |                                |           |                     |                                |           d d d            d S # 1 swxY w Y   d S r3   )r{   r  r9  rN  rA   )r8   p1p2p1_ppidp2_ppids        r<   test_oneshot_cachezTestProcess.test_oneshot_cache  s    ))++B''))''))GW---ZZ\\ 	1 	1RWWYY000RWWYY000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 ZZ\\ 	1 	1RWWYY000RWWYY000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s&   *ACCC&AEEEc                 @     fd}                                  }|                                 |                                 t          r"t	          t
          j        d|j        z                                  |           t          |          }|
                    |j                  D ]\  }} |||           t          rYt          sTt          j        j        }                      ||                                           |t$                               d S d S 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)rw  r   z didn't raise NSP and returned z instead)r&  r  )r   r   r5   rG  rb   rd   r	   )funfun_namer  r8   s      r<   assert_raises_nspzFTestProcess.test_halfway_terminated_process.<locals>.assert_raises_nsp  s    8cee  x?: Fii-0SS###!7 8 8 8 '   '   &    x+EE FFs   
5 A4A42A4z%s not in ret)r=   rT   rK   r   r#   r5   r  r7   rO   r'   iterallr   rB   r   ri  rA   rw  r    )r8   r`  rG   nsr^  r   ri  s   `      r<   test_halfway_terminated_processz+TestProcess.test_halfway_terminated_process  s-   	8 	8 	8 	8 	8$ 		 	=v{Oae$;<<<q!!!q!! 	) 	)ICc4((((  	F> 	Fw'HXXaeegg..0D0DEEEEE	F 	F 	F 	Fr>   c                    d }|                                  \  }}t          j        |j                  }|                     |                                t          j                   |                                sJ |                                 t          |          }|
                    |j                  D ]\  }} ||           t          j        |j                  sJ |                     |j        t          j                               |                     |j        d t          j                    D                        i t          _        |                     |j        d t          j                    D                        d S )Nc                 \    	  |             S # t           j        t           j        f$ r Y d S w xY wr3   )r5   rG  rd   )r^  s    r<   succeed_or_zombie_p_excz@TestProcess.test_zombie_process.<locals>.succeed_or_zombie_p_exc  s?    suu(&*=>   s   	 ++c                     g | ]	}|j         
S r-  r7   r   s     r<   r   z3TestProcess.test_zombie_process.<locals>.<listcomp>      !G!G!GA!%!G!G!Gr>   c                     g | ]	}|j         
S r-  ri  r   s     r<   r   z3TestProcess.test_zombie_process.<locals>.<listcomp>   rj  r>   )spawn_zombier5   r6   r7   rA   r  STATUS_ZOMBIErr  rD  r'   ra  rb  
pid_existsr   r  r.  _pmap)r8   rg  r  zombiezprocrc  r^  r   s           r<   test_zombie_processzTestProcess.test_zombie_process  s_   	 	 	 **,,vz**)=>>>!!!!! u%% 	) 	)IC##C(((( +++++ei///ei!G!G1D1F1F!G!G!GHHHei!G!G1D1F1F!G!G!GHHHHHr>   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 )Nr  r   r\   )r5   r6   r&   r^   rG  rr  r   rP  s      r<   $test_zombie_process_is_running_w_excz0TestProcess.test_zombie_process_is_running_w_exc"  s     NZ($*$8$;$;= = = 	@A<<>>!!!8OOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s    A**A.1A.c                 &   t          j                    }t          j        dt          j        d                    5 }|                     |                                t           j                   |j        sJ 	 d d d            d S # 1 swxY w Y   d S )Nz!psutil._psplatform.Process.statusr   r\   )	r5   r6   r&   r^   rG  rA   r  rm  r   rP  s      r<    test_zombie_process_status_w_excz,TestProcess.test_zombie_process_status_w_exc,  s     NZ;$*$8$;$;= = = 	@AQXXZZ)=>>>8OOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   <BB
B
c                    |                                  }t          j        |j                  }|j        |                                dz   f|_        |                                rJ |t          j        |j                  k    sJ d}|                     t          j        ||j	                   |                     t          j        ||j
                   |                     t          j        ||j                   |                     t          j        ||j                   |                     t          j        ||j                   d S )Nr   z4process no longer exists and its PID has been reused)r4   r5   r6   r7   r   _identrr  r   rb   rv   rw   rT   rJ   r"  )r8   subprG   rD  s       r<   test_reused_pidzTestProcess.test_reused_pid6  s   ""$$N48$$E1==??S01<<>>!!!FN48,,,,,,Dv3S!)DDDv3S!(CCCv3S!+FFFv3S!&AAAv3S!*EEEEEr>   c                    dt          j                    vr}|                     t           j        t           j        d           t          j        d          rJ |                     t          j        d                                          d           d S t          j        d          }t          rt           j	        nt          }|                     ||j                   |                     ||j                   |                     ||j                   |                     ||j                   |                     ||j                   |                     ||j        t"          j                   t'          |          }|                    |j        |j        z             D ]\  }}	  |            }|dv r|                     |j        d           0|dk    r4t          rdnd}|                     |                                |           j|dk    r|s
J |            }# t           j	        $ r Y w xY wt2          s=|                     dt          j                               t          j        d          sJ d S d S )Nr   rj   )r  r  r  zNT AUTHORITY\SYSTEMrootr   )r5   r  rD   rb   r6   rn  rA   r  r   rd   r   rK   rT   rv   rw   rJ   rW   rL   rM   r'   ra  getterssettersr  r  r	   r   )r8   rG   r  rc  r^  r   r  r   s           r<   
test_pid_0zTestProcess.test_pid_0D  sr   FKMM! 	f2FNAFFF (+++++V^A..3355q999FN1%,<f!!*#qv&&&#q{+++#qy)))#qx(((#qv&&&#q}fn=== q!!bj!899 	& 	&IC&cee ++ &$$SXq1111Z' &5<H11&D$$QZZ\\48888V^ &%%%%% &     	(MM!V[]]+++$Q'''''	( 	(''s   %
HH.-H.c                    d }d | _         t          j                    } ||                                          } |t          j                                                  }t          st          r|                     ||           d S d S d S )Nc                 B   |                      dd            |                      dd            t          rB|                      dd            |                      dd            |                      dd            t          d |                                 D                       S )NPLATHOME__CF_USER_TEXT_ENCODINGVERSIONER_PYTHON_PREFER_32_BITVERSIONER_PYTHON_VERSIONc                     g | ]Y\  }}|                     d d                               dd          |                     d d                               dd          fZS )r[   
)rz  )r   kvs      r<   r   z@TestProcess.test_environ.<locals>.clean_dict.<locals>.<listcomp>v  sp     ( ( (Q ))D"%%--dB77))D"%%--dB779 ( ( (r>   )popr   dictr0  )rI  s    r<   
clean_dictz,TestProcess.test_environ.<locals>.clean_dictm  s    EE&$EE&$ 8/6666===0$777( (WWYY( ( () ) )r>   )	maxDiffr5   r6   r  rB   copyr
   r   rA   )r8   r  rG   d1d2s        r<   test_environzTestProcess.test_environk  s    	) 	) 	) NZ		$$Z
))** 	%~ 	%R$$$$$	% 	% 	% 	%r>   c                    t          j        d          }|                                 }t          ||           |                     |gt
          j        t
          j                  }t          j        |j	                  }t          |j	                   |                                sJ |                     |j                                        d           t          r3t           r,	 |                                }n*# t          j        $ r Y d S w xY w|                                }|                     |ddd           |                                 |                     |j        d           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)stdinri   r>   r  3)ACr   )textwrapdedentr   r%   r4   rl   rm   r5   r6   r7   r/   rr  rA   ri   r   r   r   r  rd   communicate
returncode)r8   rQ   r   r;   rG   envs         r<   test_weird_environzTestProcess.test_weird_environ  sh           4%%%%##F*/*/ $ C CN59%%QU||~~**,,c222 	Z 	iikk&    
 ))++CCc22333)1-----s   &C; ;DDN)k__name__
__module____qualname____doc__r=   rH   rR   rU   rY   r.   skipIfr   re   ro   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*  r*   r,   r   r2  rB  rL  r   rf  rm  rp  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%  r'  r4  r6  r:  r=  rJ  rQ  rU  r[  rd  rr  rt  rv  rz  r  r   r  r  r-  r>   r<   r1   r1   J   s	       ))) ) )  " " "" " "	" 	" 	" X_Y,,
G 
G -,
G" " "67 7 7*8 8 8*2 2 2" " "&	' 	' 	'  	L 	L 	LH H H X_))?;;> > <;>L L L  X_Y--, , .-, X_--??U+++'/ '/ ,+ @?'/R X_^_55X_Y--(% (% .- 65(%T X_^_55X_["EFF  GF 656 X_^_554 4 654, X_^_55
6 
6 65
6 X_^_55J J 65J& X_^_55J J 65J X_^_55	4 	4 65	4/ / /" X_[.11/ / 21/
 X__o66> > 76>& 5)))X__o66B B 76 *) B ; ; ;<1 1 1  X_(/::+- +- ;:+-Z X_(/::4 4 ;:4, , ," " "% % %8G G G& X_T+,,/ / -,/5 5 5 X_T/00= = 10= X_U-..X_S/**X_T+,,7 7 -, +* /.7 X_Y--7 7 .-7 X_Y--7 7 .-7* * *X< < <	: 	: 	:/ / /A A A X_))?;;%( %( <;%(N X_))?;;? ? <;? X_))?;;F F <;F( X_S/**X_X788. . 98 +*.D X_S/**X_X788; ; 98 +*;0 X_Y--- - .-- U+++X_W&(JKKM M LK ,+M
 
 
? ? ?1 1 1* * * : : := = => > >2 2 2(- - -? ? ?: : :,& ,& ,&\* * ** * *(1 1 1(F (F (FT X_Y--"I "I .-"IH X_Y--  .- X_Y--  .-F F F%( %( %(N X__o66% % 76%* X__o66X_Y--%. %. .- 76%. %. %.r>   r1   c                        e Zd ZdZ eed          r ej                    Z ej                    Z	 fdZ
 fdZ fdZd Z ej        dd          d	             Z xZS )
LimitedUserTestCasezRepeat the previous tests by using a limited user.
        Executed only on UNIX and only if the user who run the test script
        is root.
        r  c           	           t                      j        |i | d t          |           D             D ];}t          | |          fd}t	          | |t          j        ||                      <d S )Nc                 <    g | ]}|                     d           |S )testr   r   s     r<   r   z0LimitedUserTestCase.__init__.<locals>.<listcomp>  s)    FFFqf1E1EFFFFr>   c                 J    	               d S # t           j        $ r Y d S w xY wr3   )r5   rd   )r8   meths    r<   test_z+LimitedUserTestCase.__init__.<locals>.test_  s<    !.   s   
 "")r   __init__r   r   setattrtypes
MethodType)r8   r9   r:   attrr  r  	__class__s        @r<   r  zLimitedUserTestCase.__init__  s    EGGd-f--- GFCIIFFF C CtT**    
 dE$4UD$A$ABBBBC Cr>   c                     t                                                       t          j        d           t          j        d           d S )Ni  )r   setUprB   setegidseteuidr8   r  s    r<   r  zLimitedUserTestCase.setUp  s:    GGMMOOOJtJtr>   c                     t          j        | j                   t          j        | j                   t                                                       d S r3   )rB   r  PROCESS_UIDr  PROCESS_GIDr   tearDownr  s    r<   r  zLimitedUserTestCase.tearDown  sE    Jt'(((Jt'(((GGr>   c                     	 t          j                                        d           |                     d           d S # t           j        $ r Y d S w xY w)Nr   zexception not raised)r5   r6   r  r   rd   r<  s    r<   r  zLimitedUserTestCase.test_nice  se    2  %%b))) 		011111 &   s   &? AArj   zcauses problem as rootc                     d S r3   r-  r<  s    r<   rr  z'LimitedUserTestCase.test_zombie_process  s    Dr>   )r  r  r  r  r  rB   r  r  r  r  r  r  r  r  r.   r  rr  __classcell__)r  s   @r<   r  r    s        	 	
 72x   	&#")++K#")++K	C 	C 	C 	C 	C	 	 	 	 	
	 	 	 	 	
	2 	2 	2 
4	5	5	 	 
6	5	 	 	 	 	r>   r  c                   :    e Zd ZdZed             Zd Zd Zd ZdS )	TestPopenzTests for psutil.Popen class.c                 "    t                       d S r3   r(   )clss    r<   tearDownClasszTestPopen.tearDownClass  s    r>   c                    t           ddg}t          j        |t          j        t          j                  5 }|                                 |                                 |j         |                     t          |                     | 
                    t          t          |d           |                                 d d d            n# 1 swxY w Y   t          r6|                     |                    d          t"          j                    d S |                     |                    d          t"          j                   d S )Nrg   import time; time.sleep(60);stdoutri   r  rk   )r    r5   Popenrl   rm   r   r   r  
assertTruer   rD   rE   r   rT   r   rA   rK   rL   rM   r8   rn   procs      r<   	test_misczTestPopen.test_misc  sH    4!?@\#jo!+2 2 2 	59IIKKKNNJJOOCII&&&ngtUCCCNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  	;TYYq\\FN?;;;;;TYYq\\6>:::::s   BC

CCc                 b   t          j        t          dgt          j        t          j        t          j                  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           d S )Nz-V)r  ri   r  r   )r5   r  r    rl   rm   r  r  closedri   r  rA   r  )r8   r  s     r<   test_ctx_managerzTestPopen.test_ctx_manager  s    \:t,!+!+ *1 1 1 	 59		 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 {!!!!{!!!!z    !,,,,,s   AA#&A#c                    t           ddg}t          j        |t          j        t          j                  5 }|                                 |                                 |                     t          j        |j                   |                     t          j        |j	                   |                     t          j        |j
        t          j                   t          rpt          j        dk    r`|                     t          j        |j
        t          j                   |                     t          j        |j
        t          j                   d d d            d S # 1 swxY w Y   d S )Nrg   r  r  )r   r   )r    r5   r  rl   rm   rT   rK   rD   rb   rJ   rW   rL   rM   r   rx  ry  CTRL_C_EVENTCTRL_BREAK_EVENTr  s      r<   test_kill_terminatezTestPopen.test_kill_terminate
  sv    4!?@\#jo!+2 2 2 	;59NNIIKKKf2DNCCCf2DI>>>f2D4D$n. . . ;3+v5 ;!!&"68H"("57 7 7!!&"68H"("9; ; ;	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   DEE!$E!N)	r  r  r  r  classmethodr  r  r  r  r-  r>   r<   r  r    s`        ''  [; ; ;$	- 	- 	-; ; ; ; ;r>   r  __main__)run_from_name)Er  r,  r`   r  r  rB   rL   r  r[  rl   rx  r  r   r  r5   r   r   r   r   r   r	   r
   r   r   r   psutil._commonr   psutil._compatr   r   r   r   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/   r1   r  r  r  r  psutil.tests.runnerr  __file__r-  r>   r<   <module>r     s   & %           				        



                                                                 $ $ $ $ $ $       , , , , , ,                   ! ! ! ! ! ! # # # # # # ' ' ' ' ' ' ' ' ' ' ' ' ) ) ) ) ) ) $ $ $ $ $ $ # # # # # # ( ( ( ( ( ( ) ) ) ) ) ) - - - - - - # # # # # # $ $ $ $ $ $       # # # # # # ' ' ' ' ' ' # # # # # # # # # # # # , , , , , , # # # # # #       * * * * * * & & & & & & ) ) ) ) ) )       . . . . . . 0 0 0 0 0 0 ! ! ! ! ! ! % % % % % %^. ^. ^. ^. ^.. ^. ^. ^.L+ 	 .YRY[[A ., , , , ,k , , ,h5; 5; 5; 5; 5; 5; 5; 5;p z 111111M( r>   