
    f_                     2   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlmZ ddl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< dd-l!m=Z= dd.l!m>Z> dd/l!m?Z?  G d0 d1e2      Z@er ej                         dk(  r G d2 d3e@      ZB G d4 d5e2      ZCeDd6k(  rdd7lEmFZF  eFeG       yy)8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)MACOS_11PLUS)PYPY)
PYTHON_EXE)PYTHON_EXE_ENV)PsutilTestCase)
ThreadTask)
call_until)copyload_shared_lib)create_c_exe)create_py_exe)mock)process_namespacereap_children)retry_on_failure)sh)skip_on_access_denied)skip_on_not_implemented)wait_for_pidc                   	   e Zd ZdZd Zd Zd Zd Zd Z e	j                  e d      d        Zd	 Z e	j                  ed
      d        Zd Zd Zd Zd Zd Zd Zd Z e	j                  e d      d        Zd Z e	j                  e d      d        Z e	j                  e d       ee      d               Z e	j                  e d       e	j                  e d      d               Z  e	j                  e d       e	j                  e! d      d               Z" e	j                  e# d      d        Z$ e	j                  e# d      d        Z% e	j                  e# d      d         Z& e	j                  e# d      d!        Z' e	j                  e# d      d"        Z(d# Z) e	j                  e! d$      d%        Z* e	j                  e+ d      d&        Z, e-        e.e/       e	j                  e+ d      d'                      Z0 e-       d(        Z1d) Z2 e	j                  e3 d      d*        Z4 e	j                  e3 d      d+        Z5d, Z6d- Z7d. Z8d/ Z9 e	j                  e:d0      d1        Z;d2 Z< e	j                  e:d3      d4        Z= e	j                  e>d5       e	j                  e?d6       e	j                  e:d0      d7                      Z@ e	j                  e d      d8        ZA e	j                  e d      d9        ZBd: ZCd; ZDd< ZEd= ZFd> ZG e	j                  eH d      d?        ZI e	j                  eH d      d@        ZJ e	j                  eH d      dA        ZK e	j                  eLdB       e	j                  eMdC      dD               ZN e	j                  eLdB       e	j                  eMdC      dE               ZO e	j                  e d      dF        ZP ee       e	j                  eQxs edG      dH               ZRdI ZSdJ ZTdK ZU e-       dL        ZVdM ZWdN ZXdO ZYdP ZZdQ Z[dR Z\dS Z]dT Z^dU Z_dV Z`dW Za e	j                  e d      dX        Zb e	j                  e d      dY        Zc e	j                  e d      dZ        Zdd[ Zed\ Zf e	j                  eg d      d]        Zh e	j                  eg d       e	j                  e d       e	j                  eid^      d_                      Zjy`)aTestProcessr   c                      | j                   |i |}	 t        j                  |j                        S # t        j                  $ r | j                  |j                          w xY wN)spawn_testprocpsutilProcesspidNoSuchProcessassertPidGone)selfargskwargssprocs       ;/usr/lib/python3/dist-packages/psutil/tests/test_process.pyspawn_psproczTestProcess.spawn_psprocP   s[    ###T4V4	>>%)),,## 	uyy)	s	   3 0A#c                     t        j                         }| j                  |j                  t	        j
                                | j                  t              5  d|_        d d d        y # 1 sw Y   y xY w)N!   )r7   r8   assertEqualr9   osgetpidassertRaisesAttributeErrorr<   ps     r@   test_pidzTestProcess.test_pidZ   sR    NN		,~. 	AE	 	 	s   A))A2c                    | j                         }|j                          |j                         }t        r!| j	                  |t
        j                         n!| j	                  |t
        j                          | j                  |       y r5   )	rA   killwaitr   rD   signalSIGTERMSIGKILLassertProcessGoner<   rJ   codes      r@   	test_killzTestProcess.test_kill`   s_    	vvxT6>>2TFNN?3q!    c                    | j                         }|j                          |j                         }t        r!| j	                  |t
        j                         n!| j	                  |t
        j                          | j                  |       y r5   )rA   	terminaterN   r   rD   rO   rP   rR   rS   s      r@   test_terminatezTestProcess.test_terminatej   s_    	vvxT6>>2TFNN?3q!rV   c                 ,   t         rt        j                  nt        j                  }| j	                         }|j                  |       |j                         }t        r| j                  ||       n| j                  ||        | j                  |       y r5   )
r   rO   rQ   rP   rA   send_signalrN   r   rD   rR   )r<   sigrJ   rT   s       r@   test_send_signalzTestProcess.test_send_signalt   sk     %fnn6>>	cvvxT3'TC4(q!rV   z	not POSIXc                     t         j                  }| j                         }t        j                  dt        t        j                  d            5  | j                  t        j                  |j                  |       d d d        | j                         }t        j                  dt        t        j                  d            5  | j                  t        j                  |j                  |       d d d        y # 1 sw Y   }xY w# 1 sw Y   y xY w)Nzpsutil.os.kill side_effect)rO   rP   rA   r)   patchOSErrorerrnoESRCHrG   r7   r:   r[   EPERMAccessDenied)r<   r\   rJ   s      r@   test_send_signal_mockedz#TestProcess.test_send_signal_mocked   s    nnZZ'%++r*B
 	H f22AMM3G	H
 ZZ'%++r*B
 	G f111==#F	G 	G	H 	H	G 	Gs   ,C8,D8DDc                    t         ddg}| j                  |      }|j                         }| j                  |d       | j	                  |       t         ddg}| j                  |t
        j                        }|j                         }| j                  |d       | j	                  |       t         ddg}| j                  |      }|j                         }| j                  |d       | j	                  |       t         dd	g}| j                  |      }|j                         }| j                  |d       | j	                  |       y )
N-cpassr   z1 / 0)stderr   zimport sys; sys.exit(5);   zimport os; os._exit(5);)r!   rA   rN   rD   rR   
subprocessPIPE)r<   cmdrJ   rT   s       r@   test_wait_exitedzTestProcess.test_wait_exited   s#    4(c"vvxq!q!4)c*//:vvxq!q!4!;<c"vvxq!q!4!:;c"vvxq!q!rV   zfails on NETBSDc                 "   | j                         }t        r|j                  t        j                         | j                  t        j                  |j                  d       |j                  t        j                         | j                  t        j                  |j                  d       |j                  t        j                         | j                  |j                         t        j                          | j                  |j                         t        j                          y |j                          | j                  t        j                  |j                  d       |j                          | j                  t        j                  |j                  d       |j                          | j                  |j                         t        j                         | j                  |j                         t        j                         y )NMbP?)timeout)rA   r   r[   rO   SIGSTOPrG   r7   TimeoutExpiredrN   SIGCONTrP   rD   suspendresumerX   rI   s     r@   test_wait_stoppedzTestProcess.test_wait_stopped   sH    MM&..)f33QVVUKMM&..)f33QVVUKMM&..)QVVX7QVVX7IIKf33QVVUKHHJf33QVVUKKKMQVVXv~~6QVVXv~~6rV   c                 J   | j                         \  }}| j                  t        j                  |j                  d       | j                  t        j                  |j                  d       |j                          |j                          |j	                         }|j	                         }t        r4| j                  |t        j                          | j                  |d        y | j                  |t        j                         | j                  |t        j                         y )N{Gz?)
spawn_children_pairrG   r7   rw   rN   rX   r   rD   rO   rP   )r<   child
grandchild	child_retgrandchild_rets        r@   test_wait_non_childrenz"TestProcess.test_wait_non_children   s     !446z&//TB&//$G 	JJL	#*Y8 ^T2Y7Y7rV   c                 2   | j                         }|j                          | j                  t        j                  |j
                  d       | j                  t        j                  |j
                  d       | j                  t        |j
                  d       y )Nr}   r   )rA   namerG   r7   rw   rN   
ValueErrorrI   s     r@   test_wait_timeoutzTestProcess.test_wait_timeout   sg    	&//>&//;*affb1rV   c                 \   | j                         }| j                  t        j                  |j                  d       |j                          t        j                         t        z   }t        j                         |k  r	 |j	                  d      }n| j                  d      t        r"| j                  |t        j                          n | j                  |t        j                         | j                  |       y # t        j                  $ r Y nw xY wt        j                         |k  r)Nr   ru   )rA   rG   r7   rw   rN   rM   timer   failr   rD   rO   rQ   rP   rR   )r<   rJ   stop_atrT   s       r@   test_wait_timeout_nonblockingz)TestProcess.test_wait_timeout_nonblocking   s    &//;	))+.iikG#vvay ))I&&TFNN?3T6>>2q! (( 	 iikG#s   ?C< <DDc                    t        j                         }|j                  d       |j                  d       t        d      D ]<  }|j                  d       }| j	                  |t
               | j                  |d       > | j                  t              5  |j                  d       d d d        y # 1 sw Y   y xY w)Nrt   )intervald           r   )	r7   r8   cpu_percentrangeassertIsInstancefloatassertGreaterEqualrG   r   )r<   rJ   _percents       r@   test_cpu_percentzTestProcess.test_cpu_percent   s    NN	u%	u%s 	2AmmTm2G!!'51##GS1	2 z* 	'MM2M&	' 	' 	's   B44B=c                     t        j                  dd       5 }t        j                         j	                          |j
                  sJ 	 d d d        y # 1 sw Y   y xY w)Nzpsutil.cpu_count)return_value)r)   rb   r7   r8   r   called)r<   ms     r@   test_cpu_percent_numcpus_nonez)TestProcess.test_cpu_percent_numcpus_none   sF    ZZ*> 	!NN((*88O8	 	 	s   1AAc           
         t        j                         j                         }|j                  dkD  s|j                  dkD  sJ |       |j
                  dk\  sJ |       |j                  dk\  sJ |       t        r|j                  dk\  sJ |       |j                  D ]5  }t        j                  dt        j                  t        ||                   7 y )Nr   z%H:%M:%S)r7   r8   	cpu_timesusersystemchildren_userchildren_systemr   iowait_fieldsr   strftime	localtimegetattr)r<   timesr   s      r@   test_cpu_timeszTestProcess.test_cpu_times   s     **,

S ellS&8@5@9""c)050)$$+2U2+<<3&--&MM 	LDMM*dnnWUD5I&JK	LrV   c                 \   t        j                         j                         d d \  }}t        j                         d d \  }}t        ||g      t        ||g      z
  dkD  r| j                  d|d|      t        ||g      t        ||g      z
  dkD  r| j                  d|d|      y )N   皙?
expected: 	, found: )r7   r8   r   rE   r   maxminr   )r<   	user_timekernel_timeutimektimes        r@   test_cpu_times_2zTestProcess.test_cpu_times_2
  s    !'!1!;!;!=bq!A	;xxz"1~u
 E"#c9e*<&==D))	JKKe$%[%,@(AASH))LMM IrV   znot supportedc                 8   t        j                         }|j                         }| j                  |d       t        j                         dk(  r| j                  |d       | j                  |j                         t        t        j                                      y Nr   rm   )r7   r8   cpu_numr   	cpu_countrD   assertInr   )r<   rJ   nums      r@   test_cpu_numzTestProcess.test_cpu_num  sl    NNiikQ'"S!$aiik5)9)9);#<=rV   c                 4   | j                         }t        j                         }|j                         }t        ||z
        }|dkD  r| j	                  d|d|d|      t        j
                  dt        j                  |j                                      y )Nr   r   r   z, difference: z%Y %m %d %H:%M:%S)rA   r   create_timeabsr   r   r   )r<   rJ   nowr   
differences        r@   test_create_timezTestProcess.test_create_time   s{    iikmmo
 s*+
>))Z1  	)4>>!--/+JKrV   z
POSIX onlyc                     t        j                         j                         }|;t        j                  j                  t        d            }| j                  ||       y y )Ntty)r7   r8   terminalrE   pathrealpathr.   rD   )r<   r   r   s      r@   test_terminalzTestProcess.test_terminal2  sJ    >>#,,.''""2e9-CXs+  rV   )only_ifc                 J   t        j                         }|j                         }t        t        d      5 }|j                          d d d        |j                         }t        st        s| j                  |j                  |j                         | j                  |j                  |j                         t        r| j                  |j                  |j                         | j                  |j                  |j                         nL| j                  |j                   |j                          | j                  |j"                  |j"                         |j                         }t        | j%                         d      5 }t&        r|j)                  t+        ddz  d             n|j)                  ddz         d d d        |j                         }| j                  |j                  |j                         | j                  |j"                  |j"                         | j                  |j                  |j                         | j                  |j                   |j                          t        rL| j                  |j                  |j                         | j                  |j                  |j                         t-        t/        |            D ]8  }t        r|dk\  r| j                  ||   d       | j                  ||   d       : y # 1 sw Y   xY w# 1 sw Y   axY w)Nrbwbxi@B asciir   r   )r7   r8   io_countersopenr!   readr   r   assertGreater
read_countrD   write_countr   
read_charswrite_charsr   
read_byteswrite_bytes
get_testfnr   writebytesr   len)r<   rJ   io1fio2is         r@   test_io_counterszTestProcess.test_io_counters9  s4    NNmmo*d# 	qFFH	mmo3s~~s~~>S__coo>""3>>3>>B  #//B##CNNCNNC##COOS__E mmo$//#T* 	'acGmW56g&		'
 mmoAA??s@##CNNCNNC s3x 	/AqAv##CFA.##CFA.	/=	 		' 	's   L?:LLL"z
linux onlyc                 H   fd}t        j                         t        s1| j                  j	                         d   t         j
                         | j                  t         j
                  d       | j                  t         j                  d       | j                  t         j                  d       | j                  t         j                  d       j	                         }| j                  ||       j	                  t         j                         | j                  t        j	                               t         j                  df       | j                  t              5  j	                  t         j                  d       d d d        j	                  t         j                         | j                  t        j	                               t         j                  df       j	                  t         j                  d       | j                  t        j	                               t         j                  df       | j                  t              5  j	                  t         j                  d       d d d        	 j	                  t         j                  d       | j                  t        d	      5  j	                  t         j
                  d       d d d        | j                  t        d	      5  j	                  t         j                  d       d d d        | j                  t        d
      5  j	                  d       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# t         j                  $ r Y w xY w# 1 sw Y   xY w# 1 sw Y   yxY w# 1 sw Y   y xY w)Nc                 ^    | \  }}|t         j                  k(  rd}j                  ||       y Nr   )r7   IOPRIO_CLASS_NONEionice)initioclassvaluerJ   s      r@   cleanupz.TestProcess.test_ionice_linux.<locals>.cleanupg  s-    !NGU&222HHWe$rV   r   rm   r         r      zioclass accepts no valuez$'ioclass' argument must be specified)r7   r8   r   rD   r   r   IOPRIO_CLASS_RTIOPRIO_CLASS_BEIOPRIO_CLASS_IDLE
addCleanuptuplerG   r   rg   assertRaisesRegex)r<   r   r   rJ   s      @r@   test_ionice_linuxzTestProcess.test_ionice_linuxd  s   	% NNQXXZ]F,D,DE1115//3//31115xxz& 	
))*qxxz*V-E-Eq,IJz* 	8HHV--QH7	8 	
''(qxxz*V-C-CQ,GH	''q1qxxz*V-C-CQ,GHz* 	6HHV++1H5	6	HHV++1H5 ##J0JK 	2HHV--q1	2##J0JK 	2HHV--q1	2##>
 	 HH1H	 	%	8 	8	6 	6 "" 			2 	2	2 	2	 	sN   !"M"M=!M' 4!N 3!N2NMM$'M=<M= N	NN!z!not supported on this win versionc                     t        j                         }t        s.| j                  |j	                         t         j
                         |j	                         }| j                  |j                  |       |j	                  t         j                         | j                  |j	                         t         j                         |j	                  t         j                         | j                  |j	                         t         j                         	 |j	                  t         j                         | j                  |j	                         t         j                         | j                  t        d      5  |j	                  t         j
                  d       d d d        | j                  t        d      5  |j	                  t         j                  dz          d d d        y # t         j                  $ r Y w xY w# 1 sw Y   dxY w# 1 sw Y   y xY w)Nz&value argument not accepted on Windowsrm   r   zis not a valid priority)r7   r8   r   rD   r   IOPRIO_NORMALr   IOPRIO_VERYLOW
IOPRIO_LOWIOPRIO_HIGHrg   r   	TypeErrorr   )r<   rJ   r   s      r@   test_ionice_winzTestProcess.test_ionice_win  s~    NNQXXZ)=)=>xxz$' 	
&&'V%:%:;	""#V%6%67	=HHV''( QXXZ););<##?
 	4 HHV))H3	4 ##J0IJ 	-HHV''!+,	- 	- "" 		
	4 	4	- 	-s*   G 3"G83#HG54G58HHc                    dd l }t        j                  t        j                               }t        t              D cg c]  }|j                  d      s| }}|sJ |       |D ]  }t        t        |      }| j                  |d       |t        |      v rT| j                  |t        ||             t        rU| j                  |j                  |      |j                  |             |j                  |      }| j                  t        |      d       | j                  |d   d       | j                  |d   d        y c c}w )Nr   RLIMITr   r   rm   )resourcer7   r8   rE   rF   dir
startswithr   r   rD   r    rlimit	getrlimitr   )r<   r  rJ   r   namesr   r   rets           r@   test_rlimit_getzTestProcess.test_rlimit_get  s   NN299;'KBq1<<+ABBeu 	4DFD)E##E1-s8}$  $(?@   %(2D2DU2KLhhuo  S1-''A3''A3	4 Cs   EEc                    | j                         }|j                  t        j                  d       | j	                  |j                  t        j                        d       t
        rM| j                  t        d      5  t        j                  j                  d      j                  d       d d d        | j                  t              5  |j                  t        j                  d       d d d        y # 1 sw Y   HxY w# 1 sw Y   y xY w)N)rn   rn   zcan't use prlimitr   )rn   rn   rn   )rA   r  r7   RLIMIT_NOFILErD   r   r   r   _psplatformr8   rG   rI   s     r@   test_rlimit_setzTestProcess.test_rlimit_set  s    	%%v.&"6"67@ ''
4GH 8""**1-44Q78z* 	6HHV))95	6 	68 8	6 	6s   </C2!C>2C;>Dc                    t        j                         }| j                         }|j                  t         j                        \  }}	 |j                  t         j                  d|f       t        |d      5 }|j                  d       d d d        | j                  t              5 }t        |d      5 }|j                  d       d d d        d d d        | j                  t        rj                  j                  nj                  d   t        j                         |j                  t         j                  ||f       | j                  |j                  t         j                        ||f       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# |j                  t         j                  ||f       | j                  |j                  t         j                        ||f       w xY w)N   r   s   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXs  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXr   )r7   r8   r   r  RLIMIT_FSIZEr   r   rG   IOErrorrD   r   	exceptionrd   EFBIG)r<   rJ   testfnsofthardr   excs          r@   test_rlimitzTestProcess.test_rlimit  s|   NN"XXf112
d	JHHV((4,7fd# %q$% ""7+ )s&$' )1GGK()) '*##a0@%++ HHV((4,7QXXf&9&9:T4LI% %
) )) ) HHV((4,7QXXf&9&9:T4LIsV   .F 6E1F %F	2E=F	AF 1E:6F =F	F		FF AG*c                    t        j                         }|j                  t         j                        \  }}	 |j                  t         j                  d|f       |j                  t         j                  t         j                  |f       t        | j                         d      5 }|j                  d       d d d        |j                  t         j                  ||f       | j                  |j                  t         j                        ||f       y # 1 sw Y   ]xY w# |j                  t         j                  ||f       | j                  |j                  t         j                        ||f       w xY w)Nr  r   s   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX)	r7   r8   r  r  RLIM_INFINITYr   r   r   rD   )r<   rJ   r  r  r   s        r@   test_rlimit_infinityz TestProcess.test_rlimit_infinity  s    NNXXf112
d	JHHV((4,7HHV((6+?+?*FGdoo'. %!$% HHV((4,7QXXf&9&9:T4LI	% % HHV((4,7QXXf&9&9:T4LIs%   A,D $D6D DD AE3c                     t        j                         }|j                  t         j                        \  }}| j	                  t         j
                  |       |j                  t         j                  ||f       y r5   )r7   r8   r  r  rD   r  )r<   rJ   r  r  s       r@   test_rlimit_infinity_valuez&TestProcess.test_rlimit_infinity_value  sV     NNXXf112
d--t4	$$tTl3rV   c                 \   t        j                         }t        r	 |j                         }n|j                         }t               5  |j                         }| j                  ||dz          d d d        y # t         j                  $ r t        j                  d      w xY w# 1 sw Y   y xY w)N$on OpenBSD this requires root accessrm   )	r7   r8   r	   num_threadsrg   unittestSkipTestr$   rD   )r<   rJ   step1step2s       r@   test_num_threadszTestProcess.test_num_threads  s     NNP MMOE\ 	/MMOEUEAI.	/ 	/ && P''(NOOP
	/ 	/s   A6 &B"6)B"B+zWINDOWS onlyc                 l    t        j                         }| j                  |j                         d       y r   )r7   r8   r   num_handlesrI   s     r@   test_num_handleszTestProcess.test_num_handles  s&     NN1==?A.rV   c                 D   t        j                         }t        r	 |j                         }n|j                         }t               5  |j                         }| j                  t        |      t        |      dz          |d   }| j                  |j                  |d          | j                  |j                  |d          | j                  |j                  |d          d d d        y # t         j                  $ r t        j                  d      w xY w# 1 sw Y   y xY w)Nr  rm   r   r   )r7   r8   r	   threadsrg   r   r!  r$   rD   r   idr   system_time)r<   rJ   r"  r#  athreads        r@   test_threadszTestProcess.test_threads  s    NNP		 IIKE\ 	>IIKESZUa8AhGWZZ4W..
;W00'!*=	> 	> && P''(NOOP
	> 	>s   C* BD*)DDc           	      *   | j                         }t        r	 |j                          | j                  |j                         j                  t        |j                         D cg c]  }|j                   c}      d       | j                  |j                         j                  t        |j                         D cg c]  }|j                   c}      d       y # t        j                  $ r t        j                  d      w xY wc c}w c c}w )Nr  r   )delta)rA   r	   r)  r7   rg   r   r!  assertAlmostEqualr   r   sumr   r   r+  )r<   rJ   r   s      r@   test_threads_2zTestProcess.test_threads_2-  s     P		 	KKMaiik223 	 	

 	KKM  		4145 	 	
 && P''(NOOP 3
 5s   C #D>D)Dc                    t        j                         }|j                         d d \  }}|j                         }| j	                  |d       | j	                  |d       d gdz  }|j                         d d \  }}|j                         }| j	                  ||       | j                  ||       | j	                  ||       ~t        r\|j                         }	| j                  |	j                  |	j                         | j                  |	j                  |	j                         |j                         }	|	j                  D ]  }
| j                  t        |	|
      d         y )Nr   r   i` )r7   r8   memory_infomemory_percentr   r   r   rD   rsswsetvmspagefiler   r   )r<   rJ   rss1vms1percent1memarrrss2vms2percent2memr   s              r@   test_memory_infozTestProcess.test_memory_infoB  s.   NN ]]_Ra(
d##%4#4# '!]]_Ra(
d##% 	4&d+8X.--/CSWWchh/SWWcll3mmoKK 	;D##GC$6:	;rV   c                    t        j                         }t        j                         j                  }|j	                         }|j
                  D ]M  }t        ||      }| j                  |d||f       |dk(  rt        st        r7| j                  |||||f       O t        st        st        r| j                  |j                  d       t        r9| j                  |j                  d       | j                  |j                  d       y y )Nr   )msgr8  )r7   r8   virtual_memorytotalmemory_full_infor   r   r   r
   r   assertLessEqualr   r   usspssswap)r<   rJ   rF  rA  r   r   s         r@   test_memory_full_infoz!TestProcess.test_memory_full_infoa  s    NN%%'--  "KK 	IDC&E##E14-#@u}  D%3G H	I Gu##CGGQ/##CGGQ/##CHHa0 rV   c                    t        j                         }|j                         }| j                  t	        |      t	        t        |                   |j                  d      }|D ]@  }|j                  j                  d      r t        j                  j                  |j                        sJ |j                         t        re	 t        j                  j                  |j                        s:t        j                  j                  |j                        sJ |j                         dt        j                  j#                  |j                        vs	 t        j$                  |j                        }t%        j&                  |j(                        r2J |j                          |D ][  }|j,                  D ]J  }t/        ||      }	|dk(  r|dv r
|	rJ |	       | j1                  |	t2        t4        f       |	d	k\  rEJ |	        ] y # t        $ rN t        s t        d      5 }|j!                         }d d d        n# 1 sw Y   nxY wd|j                  z  vr Y w xY w# t*        $ r Y w xY w)
NF)grouped[z/proc/self/smapsz%s (deleted)64r   )addrpermsr   )r7   r8   memory_mapsrD   r   setr   r  rE   isabsr   existsislinkAssertionErrorr   r   r   basenamestatS_ISREGst_moder   r   r   r   intr   )
r<   rJ   mapsext_mapsntr   datastfnamer   s
             r@   test_memory_mapszTestProcess.test_memory_mapsq  s   NN}}TCD	N3===/ 	EB77%%c*ww}}RWW-6rww6-&!ww~~bgg6"''..GG; #77#    277#3#3BGG#<<E!#!1B $(<<

#;DRWWD#;7	E8  		-B -E*F?-- '%'5))%#t= A:,u,:-		-) * &$! "++=!> 0!'(vvx0 0 0-7tC %  D&   1 ! !s=   A#HI%I"&I 7	I" I	I"!I"%	I21I2c                    t        j                         }t               5 }d }|j                         D cg c]  } ||j                         }}| j                   ||      |       d d d        y c c}w # 1 sw Y   y xY w)Nc                 z    t         j                  j                  t         j                  j                  |             S r5   )rE   r   r   normcase)rJ   s    r@   normpathz8TestProcess.test_memory_maps_lists_lib.<locals>.normpath  s&    ww''(8(8(;<<rV   )r7   r8   r&   rS  r   r   )r<   rJ   r   rh  r   libpathss         r@   test_memory_maps_lists_libz&TestProcess.test_memory_maps_lists_lib  ss     NN " 	4d= 34--/BQ(BHBMM(4.(3	4 	4
 C	4 	4s   A6A1A61A66A?c                     t        j                         }|j                          | j                  t        |j                  d       t
        st        st        r|j                  d       y y )Nz?!?)memtyperI  )r7   r8   r5  rG   r   r   r   r   rI   s     r@   test_memory_percentzTestProcess.test_memory_percent  sR    NN	*a&6&6FEWU+ %rV   c                     | j                         }|j                         sJ |j                         sJ |j                          |j                          |j                         rJ |j                         rJ y r5   )rA   
is_runningrM   rN   rI   s     r@   test_is_runningzTestProcess.test_is_running  s^    ||~~||~~		<<>!!<<>!!>rV   c                 l   | j                         }|j                         }	 | j                  |t               t        |ddg      }| j                  |d       y # t        $ r t
        rXt        |      t        t              k(  r=t        j                  j                  }| j                   ||       |t                     npt        j                  d   dt        j                  d   }	 | j                  |j                  |d      t        j                  |d             n# t        $ r Y nw xY wY w xY w)Nr   .rm   r_   rj   zimport os; print('hey')hey)rA   exerD   r!   rX  r   r   rE   r   rg  sysversion_inforeplacer.   )r<   rJ   rt  rg  verouts         r@   test_exezTestProcess.test_exe  s   eeg	S*-, #t678e$-  	3s8s:677++  #0DE "%!1!1!!4c6F6Fq6IJ$$C,j.@.@b.I & #	s6   A BD3*6D! D3!	D-*D3,D--D32D3c                    t         ddg}| j                  |      }t        st        st        r(| j                  |j                         d   t                y t        rgt        ra|j                         d   }|t         k7  rE| j                  dj                  |j                         dd        dj                  |dd               y | j                  dj                  |j                               dj                  |             y )Nrj   zimport time; time.sleep(60)r    rm   )
r!   rA   r   r	   r   rD   cmdliner   r   join)r<   r}  rJ   pyexes       r@   test_cmdlinezTestProcess.test_cmdline  s    t%BCg& WQYY[^Z8		AJ&$$QR1388GABK3H SXXaiik2CHHW4EFrV   zbroken on PYPYc                 d   t         g}|j                  dgdz         |j                  ddg       | j                  |      }t        r"	 | j	                  |j                         |       y | j	                  |j                         |       y # t        j                  $ r | j                  d      w xY w)Nz-v2   rj   import time; time.sleep(10)z#OPENBSD: process turned into zombie)	r!   extendrA   r	   rD   r}  r7   ZombieProcessskipTest)r<   r}  rJ   s      r@   test_long_cmdlinezTestProcess.test_long_cmdline  s    ,v{#;<=g&K  g6 QYY['2 '' Kmm$IJJKs    B
 
%B/c                 D   | j                         }|j                         j                         }t        j                  j                  t        j                  j                  t        j                              j                         }|j                  |      s	J ||f       y r5   )
rA   r   lowerrE   r   rY  r   ru  
executabler  )r<   rJ   r   r  s       r@   	test_namezTestProcess.test_name  so    vvx~~  !1!1#..!ABHHJ%4t}4%rV   zunreliable on PYPYc                 H   t        | j                  d            }|ddg}| j                  |      }t        r?	 | j	                  |j                         t        j                  j                  |             y | j	                  |j                         t        j                  j                  |             y # t        $ rc |j                         t        j                  k(  r>t        j                  j                  |      j                  |j                               sJ  Y y w xY w)N01234567890123456789suffixrj   r  )r(   r   rA   r	   rD   r   rE   r   rY  rX  statusr7   STATUS_ZOMBIEr  r<   r  r}  rJ   s       r@   test_long_namezTestProcess.test_long_name  s    doo5EoFG$ =>g&  277+;+;E+BC QVVXrww'7'7'>? " 88:!5!5577++E2==affhGGG Hs   =B5 5A)D! D!zbroken on SUNOSzbroken on AIXc                    t        | j                  d            }|ddg}| j                  |      }| j                  |j	                         |       | j                  |j                         t        j                  j                  |             | j                  t        j                  j                  |j                               t        j                  j                  |             y )Nz	foo bar )r  rj   r  )r(   r   rA   rD   r}  r   rE   r   rY  rg  rt  r  s       r@   test_prog_w_funky_namez"TestProcess.test_prog_w_funky_name  s     doo[oAB$ =>g&g.277#3#3E#:;))!%%'2BGG4D4DU4KLrV   c                 j   t        j                         }|j                         \  }}}| j                  |t	        j
                                | j                  |t	        j                                t        t        d      r3| j                  t	        j                         |j                                y y N	getresuid)	r7   r8   uidsrD   rE   getuidgeteuidhasattrr  r<   rJ   real	effectivesaveds        r@   	test_uidszTestProcess.test_uids(  y    NN!"iryy{+BJJL1 2{#R\\^QVVX6 $rV   c                 j   t        j                         }|j                         \  }}}| j                  |t	        j
                                | j                  |t	        j                                t        t        d      r3| j                  t	        j                         |j                                y y r  )	r7   r8   gidsrD   rE   getgidgetegidr  	getresgidr  s        r@   	test_gidszTestProcess.test_gids6  r  rV   c                    fd}t        j                         | j                  t        j                  d       j	                         }| j                  ||       t        rd }t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  fD ]  }| j                  |      5  	 j	                  |       j	                         }|t         j                  t         j                  t         j                  fv r||k(  s|(|}| j                  ||       n| j                  ||       	 d d d         y 	 t!        t"        d      rT| j                  t#        j$                  t"        j&                  t#        j(                               j	                                j	                  d       | j                  j	                         d       t!        t"        d      rT| j                  t#        j$                  t"        j&                  t#        j(                               j	                                t*        s2j	                  d       | j                  j	                         d       y y # t         j                  $ r Y Tw xY w# 1 sw Y   xY w# t         j                  $ r Y y w xY w)Nc                 \    	 j                  |        y # t        j                  $ r Y y w xY wr5   )nicer7   rg   )r   rJ   s    r@   r   z&TestProcess.test_nice.<locals>.cleanupE  s+    t&& s    ++str)priogetpriorityrm   r   )r7   r8   rG   r   r  r   r   IDLE_PRIORITY_CLASSBELOW_NORMAL_PRIORITY_CLASSNORMAL_PRIORITY_CLASSABOVE_NORMAL_PRIORITY_CLASSHIGH_PRIORITY_CLASSREALTIME_PRIORITY_CLASSsubTestrD   rg   r  rE   r  PRIO_PROCESSrF   r   )r<   r   r   highest_prior  new_priorJ   s         @r@   	test_nicezTestProcess.test_niceD  s1   	 NN)QVVU3vvx&L**22,,22**.. = \\t\, ==t $%668
  ">>"66"::$ 
  (4/<3G/3 $ 0 0< H ,,Xt<)= ==<2}-$$r		Daffh q	  1-2}-$$r		Daffh
 FF1I$$QVVXq1 A ".. = =L && sD   J3J+A0J3'D0K  J0,J3/J00J33J=	 KKc                     t        j                         }| j                  |j                         t         j                         y r5   )r7   r8   rD   r  STATUS_RUNNINGrI   s     r@   test_statuszTestProcess.test_status  s*    NNV%:%:;rV   c                    | j                         }|j                         }t        r|j                  d      \  }}t	        j
                         }|j                  d      rt        j                  d      | j                  ||       dt        j                  v r$| j                  |t        j                  d          y y | j                  |t	        j
                                y )N\$zrunning as service account
USERDOMAIN)rA   usernamer   splitgetpassgetuserendswithr   r!  rD   rE   environ)r<   rJ   r  domaingetpass_users        r@   test_usernamezTestProcess.test_username  s    ::<'~~d3FH"??,L$$S) ''(DEEX|4rzz)  L)AB * Xw'89rV   c                     | j                         }| j                  |j                         t        j                                y r5   )rA   rD   cwdrE   getcwdrI   s     r@   test_cwdzTestProcess.test_cwd  s,    "))+.rV   c                 d    t         ddg}| j                  |      }t        |j                  d       y )Nrj   z/import os, time; os.chdir('..'); time.sleep(60)z#ret == os.path.dirname(os.getcwd()))r!   rA   r%   r  )r<   rq   rJ   s      r@   
test_cwd_2zTestProcess.test_cwd_2  s3    =

 c"155?@rV   c           	         t        j                         }|j                         }|sJ |       | j                  |j                  |       t	        t
        d      r8| j                  |t        t        j                  |j                                     | j                  t        |      t        t        |                   t        t        t        t        j                  d                        }|D ]  }|j                  |g       | j                  |j                         |g       t	        t
        d      rF| j                  |j                         t        t        j                  |j                                     t	        |d      s| j                  |j                         d   |j                                 |j                  g        t        r9| j                  |j                         |j                   j#                                n | j                  |j                         |       t	        t
        d      rF| j                  |j                         t        t        j                  |j                                     | j%                  t&        |j                  d       |j                  |       |j                  t        |             |j                  t)        |             y )Nsched_getaffinityTpercpunum_cpur   rm   )r7   r8   cpu_affinityr   r  rE   rD   listr  r9   r   rT  r   r   r  r   _proc_get_eligible_cpusrG   r   r   )r<   rJ   initialall_cpusns        r@   test_cpu_affinityzTestProcess.test_cpu_affinity  s   NN.."w02*+Wd2+?+?+F&GHWs3w<'89c&"4"4D"ABCD 		CANNA3Q^^-s3r./  NN$d2+?+?+F&G q)$  !1!!4aiikB		C 	
rQ^^-qww/I/I/KLQ^^-x82*+ $r';';AEE'B"C 	)Q^^Q7	w	s8}%	uX'rV   c                    | j                         }t        t        j                  d            dz   g}| j	                  t
        |j                  |       | j	                  t
        |j                  t        dd             | j	                  t        |j                  ddg       | j	                  t
        |j                  ddg       y )	NTr  
   i'  i*  r   1r   )	rA   r   r7   r   rG   r   r  r   r   )r<   rJ   invalid_cpus      r@   test_cpu_affinity_errsz"TestProcess.test_cpu_affinity_errs  s    6++489B>?*annkB*anneE56IJ)Q^^aX>*annq"g>rV   c                    t        j                         }|j                         }|sJ |       | j                  |j                  |       t	        |      dkD  r|d d }g }t        t	        |      dz         D ]:  }t        j                  ||      D ]  }|s|j                  t        |             ! < |D ]E  }|j                  |       | j                  t        |j                               t        |             G y )N   rm   )r7   r8   r  r   r   r   	itertoolscombinationsappendr  rD   sorted)r<   rJ   r  combosr   subsetcombos          r@   "test_cpu_affinity_all_combinationsz.TestProcess.test_cpu_affinity_all_combinations  s    NN.."w0 w<"crlGs7|a'( 	0A#00!< 0MM$v,/0	0
  	FENN5!VANN$45ve}E	FrV   zbroken on BSDzunreliable on APPVEYORc                    t        j                         }| j                         }|j                         }| j	                  ||       t        |d      5 }|j                  d       |j                          t        |j                  dt        |      z        }|D cg c]+  }t        j                  j                  |j                        - }}| j                  t        j                  j                  |      |       t        r3|D ].  }|j                  |k(  s| j                  |j                   d       0 d d d        |D ]2  }t        j                  j#                  |j                        r-J |        d|z  }| j%                  t&        d|g      }t)        d      D ]a  }|j                         D cg c]+  }t        j                  j                  |j                        - }}||v r nFt+        j,                  d       c | j                  t        j                  j                  |             |D ](  }t        j                  j#                  |      r#J |        y c c}w # 1 sw Y   /xY wc c}w )	Nr   s   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzlen(ret) != %ir  z2import time; f = open(r'%s', 'r'); time.sleep(60);rj   r   r}   )r7   r8   r   
open_filesassertNotInr   r   flushr%   r   rE   r   rg  r   r   rD   positionisfilerA   r!   r   r   sleep)	r<   rJ   r  filesr   r   	filenamesfiler}  s	            r@   test_open_fileszTestProcess.test_open_files  s    NN"'&$ 
	>1GGK GGIq||-=E
-JKE;@Aa))!&&1AIAMM"''**62I>! >DyyF*((=>
	>  	3D77>>$)),2d2,	3 GOz49:s 	?A;<<<>Ja))!&&1JIJ"JJt		? MM"''**62I> 	.D77>>$'--'	.) B
	> 
	>& Ks,   AI"0IAI"I"10I/I""I,c                    t        j                         }t        j                  j                  }| j                         }t        |d      5 }|j                         D ]F  } ||j                         ||j                        k(  s|j                  |j                         k(  sF n, | j                  dt        |j                               z        | j                   ||j                         ||j                               t        r| j                  |j                  d       n*| j                  |j                  |j                                |j                         d   }| j                  |d   |j                         | j                  |d   |j                         | j                  |j                  |j                                d d d        y # 1 sw Y   y xY w)Nwzno file found; files=%sr   r   rm   )r7   r8   rE   r   rg  r   r   r  r   fdfilenor   reprrD   r   r  )r<   rJ   rg  r  fileobjr  ntuples          r@   test_open_files_2zTestProcess.test_open_files_2  sg   
 NN77##"&# 	;' 	TYY'8GLL+AAww'.."22	 ii-alln1EF  Xdii0(7<<2HI  "-  '..*:;\\^A&FVAY4VAY		2W\\1<<>:+	; 	; 	;s   AG"D(GGc                 $   t        j                         }| j                         }|j                         }t	        |d      }| j                  |j                         | j                  |j                         |dz          t        j                         }| j                  |j                         | j                  |j                         |dz          |j                          |j                          | j                  |j                         |       y )Nr  rm   r   )	r7   r8   r   num_fdsr   r   closerD   socket)r<   rJ   r  startr  socks         r@   test_num_fdszTestProcess.test_num_fds1  s    NN"		FC 

#eai0}}

#eai0



e,rV   z not reliable on OPENBSD & NETBSDc                    t        j                         }t        |j                               }t	        d      D ]7  }t        j                  d       t        |j                               }||kD  s7 y  | j                  d      )Nr   g?z2num ctx switches still the same after 2 iterations)r7   r8   r1  num_ctx_switchesr   r   r  r   )r<   rJ   beforer   afters        r@   test_num_ctx_switchesz!TestProcess.test_num_ctx_switches@  sq     NNQ'')*q 	AJJt**,-Ev~		
 iiLMMrV   c                 4   t        j                         }t        t        d      r2| j	                  |j                         t        j                                | j                         }| j	                  |j                         t        j                                y )Ngetppid)	r7   r8   r  rE   rD   ppidr  rA   rF   rI   s     r@   	test_ppidzTestProcess.test_ppidL  s^    NN2y!QVVXrzz|4299;/rV   c                 .   | j                         }| j                  |j                         j                  t	        j
                                t        j                         d   }| j                  t        j                  |      j                                y r   )
rA   rD   parentr9   rE   rF   r7   pidsassertIsNoner8   )r<   rJ   
lowest_pids      r@   test_parentzTestProcess.test_parentS  s`    5[[]1%
&..4;;=>rV   c                     t        j                         }| j                         \  }}| j                  |j	                         |       | j                  |j	                         |       y r5   )r7   r8   r~   rD   r  r<   r  r   r   s       r@   test_parent_multizTestProcess.test_parent_multiZ  sP    ! 446z**,e40rV   c                 H   t        j                         }|j                         sJ | j                         \  }}| j	                  |j                         d   |       | j	                  |j                         d   |       | j	                  |j                         d   |       y r   )r7   r8   parentsr~   rD   r  s       r@   test_parentszTestProcess.test_parents`  s    !~~ 446z+V4++-a0%8++-a0&9rV   c                    t        j                         }| j                  |j                         g        | j                  |j                  d      g        | j	                  d      }|j                         }|j                  d      }||fD ]s  }| j                  t        |      d       | j                  |d   j                  |j                         | j                  |d   j                         |j                         u y )NT	recursiver   )creationflagsrm   )r7   r8   rD   childrenrA   r   r9   r  )r<   r  r   	children1	children2r  s         r@   test_childrenzTestProcess.test_childreni  s    !*B/48"= !!!2OO%	OOdO3	"I. 	=HS]A.Xa[__eii8Xa[--/<	=rV   c                 `   t        j                         }| j                         \  }}| j                  |j	                         |g       | j                  |j	                  d      ||g       |j                          |j                          | j                  |j	                  d      g        y )NTr  )r7   r8   r~   rD   r  rX   rN   r  s       r@   test_children_recursivez#TestProcess.test_children_recursivex  s     ! 446z*UG4485*:MN 	

48"=rV   c                 *   t        j                  t              }t        j                         D ]  }	 ||j                         xx   dz  cc<     t        |j                         d       d   d   }t        r|dk(  r| j                  d      t        j                  |      }	 |j                  d      }| j                  t        |      t        t        |                   y # t        j                  $ r Y w xY w# t        j                   $ r Y y w xY w)	Nrm   c                     | d   S )Nrm    )r   s    r@   <lambda>z6TestProcess.test_children_duplicates.<locals>.<lambda>  s
    !A$ rV   )keyr   r   zPID 0Tr  )collectionsdefaultdictr]  r7   process_iterr  Errorr  itemsr   r  r8   r  rD   r   rT  rg   )r<   tablerJ   r9   cs        r@   test_children_duplicatesz$TestProcess.test_children_duplicates  s    '',$$& 	Aaffh1$	 U[[]7;A>SAX--((NN3	2

T
*A SVSQ[1 <<  "" 		s#   C##C< #C98C9<DDc                 t   t        j                         }| j                         \  }}|j                  d      }| j	                  t        |      d       | j	                  |d   |       | j	                  |d   |       |j                         }| j	                  |d   |       | j	                  |d   |       y )NTr  r   r   rm   )r7   r8   r~   r  rD   r   r  )r<   r  r   r   r  r  s         r@   test_parents_and_childrenz%TestProcess.test_parents_and_children  s    ! 446z??T?2X*!e,!j1$$&U+V,rV   c                 P   | j                         }|j                          t        d      D ]:  }|j                         t        j
                  k(  r nt        j                  d       < |j                          | j                  |j                         t        j
                         y )Nr   r}   )
rA   ry   r   r  r7   STATUS_STOPPEDr   r  rz   assertNotEqual)r<   rJ   r   s      r@   test_suspend_resumezTestProcess.test_suspend_resume  sv    			s 	AxxzV222JJt	 	

AHHJ(=(=>rV   c                     | j                  t        t        j                  d       | j                  t        t        j                  d       y )Nr  r   )rG   r   r7   r8   r   r<   s    r@   test_invalid_pidzTestProcess.test_invalid_pid  s.    )V^^S9*fnnb9rV   c                    t        j                         }|j                  ddg      }| j                  t	        |j                               ddg       t        j                  t        t        j                                     }|j                  dgd      }t        |d   t              s| j                  |d   d       t        j                  ddt         j                  	      5  | j                  |j                  d
gd      d
di       d d d        t        j                  ddt        j                  |j                  d      	      5  | j                  t         j                  |j                  d
g       d d d        t        j                  ddt        j                   |j                  d      	      5  | j                  |j                  d
gd      d
di       d d d        t        j                  ddt"        	      5  |j                         }| j%                  d
t        |j                                      | j                  t"              5  |j                  d
g       d d d        d d d        | j                  t&              5  |j                  d       d d d        | j                  t(              5  |j                  dg       d d d        | j                  t(              5  |j                  ddg       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   DxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nrt  r   )attrsconnectionsfoo)r<  ad_valuezpsutil.Process.niceT)createra   r  rm   bar)r7   r8   as_dictrD   r  keysr   r  
isinstancer  r)   rb   rg   r:   r9   rG   r  NotImplementedErrorr  r   r   )r<   rJ   ds      r@   test_as_dictzTestProcess.test_as_dict  s   NNIIUFOI,)E6?;NN3v{{}-.II]OeI<!M*D1Q}-u5 ZZ!$F<O<O
 	 		1	5{	 ZZ!,,QUUF;
 	O
 f22AIIfXN	O ZZ!,,QUUF;
 	
 		5	9FE?	 ZZ!$<O
 	* 		AVT!&&(^4""#67 *			)*	* y) 	IIf	z* 	IIug	z* 	&IIuen%	& 	&S	 		O 	O	 	"* *	* 	*	 		 		& 	&sm   &'L.L7'L AL9L-%L9
M9M)MLL L*-L6	2L99MMMM&c                    t        j                         }t        j                  d      5 }|j	                         5  |j                          |j                          d d d        | j                  |j                  d       d d d        t        j                  d      5 }|j                          |j                          d d d        | j                  j                  d       y # 1 sw Y   xY w# 1 sw Y   pxY w# 1 sw Y   >xY w)N$psutil._psplatform.Process.cpu_timesrm   r   r7   r8   r)   rb   oneshotr   rD   
call_countr<   rJ   r   s      r@   test_oneshotzTestProcess.test_oneshot  s    NNZZ>? 	.1  Q\\1-		. ZZ>? 	1KKMKKM	 	q) 	. 	.	 	s.   C/!C#$C/!C;#C,	(C//C8;Dc           	      $   t        j                         }t        j                  d      5 }t        j                  d      5 }|j	                         5  |j                          |j                          |j	                         5  |j                          |j                          d d d        d d d        | j                  |j                  d       | j                  |j                  d       d d d        d d d        t        j                  d      5 }|j                          |j                          d d d        | j                  j                  d       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   VxY w)NrI  z(psutil._psplatform.Process.oneshot_enterrm   r   rJ  )r<   rJ   m1m2r   s        r@   test_oneshot_twicezTestProcess.test_oneshot_twice  s0    NNZZ>? 		32FG 32YY[ &KKMKKM &&&   2  23		3 ZZ>? 	1KKMKKM	 	q)& && &3 3		3 		3	 	s`   E: E.1E"!E	#E"+A E.+E:!FEE""E+'E..E7	3E::FFc                 "   | j                         \  }}|j                         }|j                         }| j                  ||       |j                         5  | j	                  |j                         |       | j	                  |j                         |       d d d        |j                         5  | j	                  |j                         |       | j	                  |j                         |       d d d        y # 1 sw Y   cxY w# 1 sw Y   y xY wr5   )r~   r  r6  rK  rD   )r<   p1p2p1_ppidp2_ppids        r@   test_oneshot_cachezTestProcess.test_oneshot_cache  s     ))+B'')'')GW-ZZ\ 	1RWWY0RWWY0	1 ZZ\ 	1RWWY0RWWY0	1 	1	1 	1	1 	1s   AC9/AD9DDc                 Z     fd} j                         }|j                          |j                          t        r't	        t
        j                  d|j                  z          j                  |       t        |      }|j                  |j                        D ]  \  }} |||        y )Nc                     	  |        }t         r|dv ry j                  | d|d      # t        j                  $ r  t        j                  $ r Y y t        j
                  $ r t        r|dv rY y  w xY w)N)rt  r   z didn't raise NSP and returned z instead)r)  r  )r   r   r7   r  r:   rg   r	   )funfun_namer  r<   s      r@   assert_raises_nspzFTestProcess.test_halfway_terminated_process.<locals>.assert_raises_nsp#  s    e x?:iiEH#N  '' '' && x+EEs   , &A4A42A4z%s not in ret)rA   rX   rN   r   r%   r7   r  r9   rR   r*   iterall)r<   r]  rJ   nsr[  r   s   `     r@   test_halfway_terminated_processz+TestProcess.test_halfway_terminated_process  s    	& 		v{{Oaee$;<q!q! 	)ICc4(	)rV   c                 L    | j                         \  }}| j                  |       y r5   )spawn_zombieassertProcessZombie)r<   r  zombies      r@   test_zombie_processzTestProcess.test_zombie_processA  s"    **,  (rV   c                     t        j                         }t        j                  dt        j                  d            5 }|j                         sJ |j                  sJ 	 d d d        y # 1 sw Y   y xY w)Nzpsutil.Processr   r`   )r7   r8   r)   rb   r  ro  r   rM  s      r@   $test_zombie_process_is_running_w_excz0TestProcess.test_zombie_process_is_running_w_excF  s]     NNZZ&*>*>q*A
 	<<>!>88O8		 	 	s   !A**A3c                 $   t        j                         }t        j                  dt        j                  d            5 }| j                  |j                         t         j                         |j                  sJ 	 d d d        y # 1 sw Y   y xY w)Nz!psutil._psplatform.Process.statusr   r`   )	r7   r8   r)   rb   r  rD   r  r  r   rM  s      r@    test_zombie_process_status_w_excz,TestProcess.test_zombie_process_status_w_excQ  sn     NNZZ/,,Q/
 	 QXXZ)=)=>88O8	 	 	s   =BBc                 |   | j                         }t        j                  |j                        }|j                  |j	                         dz   f|_        |j                         rJ |t        j                  |j                        k7  sJ d}t        |      }|j                  |j                  |j                  z   d      D ]A  \  }}| j                  |      5  | j                  t        j                  ||       d d d        C | j                  t        j                  ||j                         | j                  t        j                  ||j                         | j                  t        j                  ||j                          | j                  t        j                  ||j"                         y # 1 sw Y   xY w)Nr   z4process no longer exists and its PID has been reusedF)clear_cache)r   )r6   r7   r8   r9   r   _identro  r*   r^  setterskillersr  r   r:   r  r  r  r  )r<   subprJ   rD  r`  r[  r   s          r@   test_reused_pidzTestProcess.test_reused_pid]  s\   ""$NN488$EE1==?S01<<>!!FNN488,,,,Dq!bjj!8eL 	GIC4( G&&v';';S#FG G	G 	v33S!&&Av33S!((Cv33S!))Dv33S!**EG Gs   "F22F;	c                    dt        j                         vrz| j                  t         j                  t         j                  d       t        j
                  d      rJ | j                  t        j                  d      j                         d       y t        j                  d      }t        rt         j                  nt        }| j                  ||j                         | j                  ||j                         | j                  ||j                         | j                  ||j                         | j                  ||j                         | j                  ||j                   t"        j$                         t'        |      }|j)                  |j*                  |j,                  z         D ]m  \  }}	  |       }|dv r| j                  |j.                  d       /|dk(  r+t        rdnd}| j                  |j1                         |       _|dk(  se|rhJ |        t2        s<| j5                  dt        j                                t        j
                  d      sJ y y # t         j                  $ r Y w xY w)Nr   rm   )r  r  r  zNT AUTHORITY\SYSTEMrootr   )r7   r  rG   r:   r8   
pid_existsrD   r  r   rg   r   rN   rX   ry   rz   rM   r[   rO   rP   r*   r^  gettersrn  r  r  r	   r   )r<   rJ   r  r`  r[  r   r  r   s           r@   
test_pid_0zTestProcess.test_pid_0n  s   FKKM!f22FNNAF ((+++V^^A.335q9NN1%,f!!*#qvv&#q{{+#qyy)#qxx(#qvv&#q}}fnn= q!bjj!89 	&IC&e ++$$SXXq1Z'5<1&D$$QZZ\48V^%%4	& MM!V[[]+$$Q'''  && s   3II54I5c                     d }d | _         t        j                         } ||j                               } |t        j                  j                               }t        st        r| j                  ||       y y y )Nc                    | j                  dd        | j                  dd        t        r6| j                  dd        | j                  dd        | j                  dd        t        | j                         D cg c]I  \  }}|j	                  dd      j	                  dd      |j	                  dd      j	                  dd      fK c}}      S c c}}w )	NPLATHOME__CF_USER_TEXT_ENCODINGVERSIONER_PYTHON_PREFER_32_BITVERSIONER_PYTHON_VERSIONr_   
)popr   dictr.  rw  )rF  kvs      r@   
clean_dictz,TestProcess.test_environ.<locals>.clean_dict  s    EE&$EE&$/66=0$7
 GGI
 Aq IIdB'//b9IIdB'//b9   s   9AC
)	maxDiffr7   r8   r  rE   copyr
   r   rD   )r<   r  rJ   d1d2s        r@   test_environzTestProcess.test_environ  s]    	  NN		$

)*~R$ &srV   z<macOS 11+ can't get another process environment, issue #2084c                    t        j                  d      }t        | j                         |      }| j	                  |gt
        j                  t
        j                        }t        j                  |j                        }t        |j                         |j                         sJ | j                  |j                  j                         d       t        rt         r	 |j#                         }n|j#                         }| j                  |ddd       |j'                          | j                  |j(                  d       y # t        j$                  $ r Y y w xY w)	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)stdinrl   rV   r  3)ACr   )textwrapdedentr'   r   r6   ro   rp   r7   r8   r9   r1   ro  rD   rl   r   r   r   r  rg   communicate
returncode)r<   rT   cexer?   rJ   envs         r@   test_weird_environzTestProcess.test_weird_environ  s        DOO-d;##F*//*// $ 
 NN599%QUU||~~**,c2Ziik ))+CCc23))1- &&  s   E EEN)k__name__
__module____qualname____doc__rA   rK   rU   rY   r]   r   skipIfr   rh   rr   r   r{   r   r   r   r   r   r   r   r   r   r   r   r   r0   r   r   r   r   r   r   r   r  r  r  r  r  r$  r'  r   r-  r-   r/   r   r2  rB  rL  r   rd  rj  rm  rp  rz  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$  r1  r3  r7  r:  rG  rN  rR  rX  ra  rf  rh  rj  rq  rv  r   r  r   r  r'  rV   r@   r3   r3   M   s   )""	" X__Y,G -G"6 X__V./7 07*8*2"&	'	LN X__))?;> <>L$ X__Y-, ., X__--?U+'/ , @'/R X__^_5X__Y-) . 6)V X__^_5X__["EF- G 6-4 X__^_54 64. X__^_5
6 6
6 X__^_5J 6J( X__^_5J 6J X__^_5	4 6	4/" X__[.1/ 2/
 X___o6> 7>& 5)X___o6
 7 * 
$ ; ;<1  X__(/:+- ;+-Z X__(/:	4 ;	4,"%:G( X__T+,3 -35 X__T/0@ 1@. X__U-.X__S/*X__T+,	M - + /	M X__Y-7 .7 X__Y-7 .7=~<:"/A X__))?;'( <'(R X__))?;? <? X__))?;F <F( X__S/*X__X78. 9 +.D X__S/*X__X78; 9 +;8 X__Y-- .- U+X__W&(JKN L ,N0?1 : :=>2(-?:5&n**(1$)L X__Y-) .) X__Y- . X__Y-	 .	F"%(N X___o6% 7%0 X___o6X__Y-X__F%.	 . 7%.rV   r3   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 | t        |       D cg c]  }|j                  d      s| c}D ]4  }t	        | |      fd}t        | |t        j                  ||              6 y c c}w )Ntestc                 H    	          y # t         j                  $ r Y y w xY wr5   )r7   rg   )r<   meths    r@   test_z+LimitedUserTestCase.__init__.<locals>.test_  s%    !.. s    !!)r   __init__r  r  r   setattrtypes
MethodType)r<   r=   r>   r   attrr  r  	__class__s         @r@   r  zLimitedUserTestCase.__init__  sv    EGd-f- %(IFqf1EF 	CtT* dE$4$4UD$AB	CFs   B B c                     t               j                          t        j                  d       t        j                  d       y )Ni  )r   setUprE   setegidseteuidr<   r  s    r@   r  zLimitedUserTestCase.setUp  s&    GMMOJJtJJtrV   c                     t        j                  | j                         t        j                  | j                         t               j                          y r5   )rE   r  PROCESS_UIDr  PROCESS_GIDr   tearDownr  s    r@   r  zLimitedUserTestCase.tearDown  s5    JJt''(JJt''(GrV   c                     	 t        j                         j                  d       | j                  d      # t         j                  $ r Y y w xY w)Nr   zexception not raised)r7   r8   r  r   rg   r9  s    r@   r  zLimitedUserTestCase.test_nice  sH    8 %%b) ii 677 && s   #6 AArm   zcauses problem as rootc                      y r5   r'  r9  s    r@   rf  z'LimitedUserTestCase.test_zombie_process  s    rV   )r  r  r  r  r  rE   r  r  r  r  r  r  r  r  r   r  rf  __classcell__)r  s   @r@   r  r    se    	 2x #"))+K#"))+K	C	
	
	8 
4	5	 
6	rV   r  c                   2    e Zd ZdZed        Zd Zd Zd Zy)	TestPopenzTests for psutil.Popen class.c                     t                y r5   r+   )clss    r@   tearDownClasszTestPopen.tearDownClass  s    rV   c                 b   t         ddg}t        j                  |t        j                  t        j                  t
              5 }|j                          |j                          |j                   | j                  t        |             | j                  t        t        |d       |j                          d d d        t        r1| j!                  j#                  d      t$        j&                          y | j!                  j#                  d      t$        j&                         y # 1 sw Y   pxY w)Nrj   import time; time.sleep(60);stdoutrl   r  r>  rn   )r!   r7   Popenro   rp   r"   r   r   r  
assertTruer  rG   rH   r   rX   r   rD   rN   rO   rP   r<   rq   procs      r@   	test_misczTestPopen.test_misc   s     4!?@\\????	
 	
 IIKNNJJOOCI&ngtUCNN	 TYYq\FNN?;TYYq\6>>:	 	s   A3D%%D.c                    t        j                  t        dgt        j                  t        j                  t        j                  t
              5 }|j                          d d d        j                  j                  sJ |j                  j                  sJ |j                  j                  sJ | j                  |j                  d       y # 1 sw Y   nxY w)Nz-V)r  rl   r  r  r   )r7   r  r!   ro   rp   r"   r  r  closedrl   r  rD   r  )r<   r  s     r@   test_ctx_managerzTestPopen.test_ctx_manager6  s    \\????//
 	 	 {{!!!!{{!!!!zz    !,	 	s   CCc                    t         ddg}t        j                  |t        j                  t        j                  t
              5 }|j                          |j                          | j                  t        j                  |j                         | j                  t        j                  |j                         | j                  t        j                  |j                  t        j                         t        rr| j                  t        j                  |j                  t        j                         | j                  t        j                  |j                  t        j                          d d d        y # 1 sw Y   y xY w)Nrj   r  r  )r!   r7   r  ro   rp   r"   rX   rN   rG   r:   rM   r[   rO   rP   r   CTRL_C_EVENTCTRL_BREAK_EVENTr  s      r@   test_kill_terminatezTestPopen.test_kill_terminateD  s    4!?@\\????	
 	
 NNIIKf22DNNCf22DII>$$d&6&6 !!(($*:*:F<O<O !!(($$++#	 	 	s   D&E22E;N)	r  r  r  r  classmethodr  r  r  r  r'  rV   r@   r  r    s&    ' ;,-rV   r  __main__)run_from_name)Hr  r*  rd   r  r  rE   rO   r  rZ  ro   ru  r  r   r  r   r7   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/   r0   r1   r3   r  r  r  r  psutil.tests.runnerr  __file__r'  rV   r@   <module>r     s   &     	     
                $  ,    ! # ' ' ) $ # ( ) - # $ %  # ' ' # # , % &  * & )  . 0 %L.. L.h, 	YRYY[A.k .lE EP z1( rV   