
    ztf                     J   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? dd0l"m@Z@ dd1l"mAZA  G d2 d3e4      ZBer ej                         dk(  r G d4 d5eB      ZD G d6 d7e4      ZEeFd8k(  rdd9lGmHZH  eHeI       yy):Tests for psutil.Process class.    N)AIX)BSD)LINUX)MACOS)NETBSD)OPENBSD)OSX)POSIX)SUNOS)WINDOWS)	open_text)PY3)FileNotFoundError)long)redirect_stderr)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)	QEMU_USER)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                   L   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 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       ee      d               Z e	j                  e  d       e	j                  e d      d               Z! e	j                  e  d       e	j                  e" d      d               Z# e	j                  e$ d      d        Z% e	j                  e$ d      d         Z& e	j                  e$ d      d!        Z' e	j                  e$ d      d"        Z( e	j                  e$ d      d#        Z)d$ Z* e	j                  e" d%      d&        Z+ e	j                  e, d      d'        Z- e.        e/e0       e	j                  e, d      d(                      Z1 e.       d)        Z2d* Z3 e	j                  e4 d      d+        Z5 e	j                  e4 d      d,        Z6d- Z7d. Z8 e	j                  ed      d/        Z9d0 Z: e	j                  e;d1      d2        Z<d3 Z= e	j                  e;xs ed4       e	j                  ed5      d6               Z> e	j                  e?d7       e	j                  e@d8       e	j                  e;d1       e	j                  ed9      d:                             ZA e	j                  e d      d;        ZB e	j                  e d      d<        ZCd= ZD e	j                  ed      d>        ZEd? ZFd@ ZGdA ZH e	j                  eI d      dB        ZJ e	j                  eI d      dC        ZK e	j                  eI d      dD        ZL e	j                  eMdE       e	j                  eNdF      dG               ZO e	j                  eMdE       e	j                  eNdF      dH               ZP e	j                  e d      dI        ZQ ee       e	j                  eRxs edJ      dK               ZSdL ZTdM ZUdN ZV e	j                  ed       e.       dO               ZWdP ZXdQ ZYdR ZZdS Z[dT Z\dU Z]dV Z^dW Z_dX Z`dY ZadZ Zb e	j                  e d      d[        Zc e	j                  e d      d\        Zd e	j                  e d      d]        Zed^ Zfd_ Zg e	j                  eh d      d`        Zi e	j                  eh d       e	j                  e d       e	j                  ejda       e	j                  edb      dc                             Zkyd)e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       c/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/psutil/tests/test_process.pyspawn_psproczTestProcess.spawn_psprocR   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!   )r9   r:   assertEqualr;   osgetpidassertRaisesAttributeErrorr>   ps     rB   test_pidzTestProcess.test_pid\   sR    NN		,~. 	AE	 	 	s   A))A2c                    | j                         }|j                          |j                         }t        r!| j	                  |t
        j                         n!| j	                  |t
        j                          | j                  |       y r7   )	rC   killwaitr   rF   signalSIGTERMSIGKILLassertProcessGoner>   rL   codes      rB   	test_killzTestProcess.test_killb   s_    	vvxT6>>2TFNN?3q!    c                    | j                         }|j                          |j                         }t        r!| j	                  |t
        j                         n!| j	                  |t
        j                          | j                  |       y r7   )rC   	terminaterP   r   rF   rQ   rR   rT   rU   s      rB   test_terminatezTestProcess.test_terminatel   s_    	vvxT6>>2TFNN?3q!rX   c                 ,   t         rt        j                  nt        j                  }| j	                         }|j                  |       |j                         }t        r| j                  ||       n| j                  ||        | j                  |       y r7   )
r   rQ   rS   rR   rC   send_signalrP   r   rF   rT   )r>   sigrL   rV   s       rB   test_send_signalzTestProcess.test_send_signalv   sk     %fnn6>>	cvvxT3'TC4(q!rX   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)rQ   rR   rC   r+   patchOSErrorerrnoESRCHrI   r9   r<   r]   EPERMAccessDenied)r>   r^   rL   s      rB   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"   rC   rP   rF   rT   
subprocessPIPE)r>   cmdrL   rV   s       rB   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!rX   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)rC   r   r]   rQ   SIGSTOPrI   r9   TimeoutExpiredrP   SIGCONTrR   rF   suspendresumerZ   rK   s     rB   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~~6rX   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_pairrI   r9   ry   rP   rZ   r   rF   rQ   rR   )r>   child
grandchild	child_retgrandchild_rets        rB   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7rX   c                 2   | j                         }|j                          | j                  t        j                  |j
                  d       | j                  t        j                  |j
                  d       | j                  t        |j
                  d       y )Nr   r   )rC   namerI   r9   ry   rP   
ValueErrorrK   s     rB   test_wait_timeoutzTestProcess.test_wait_timeout   sg    	&//>&//;*affb1rX   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   rw   )rC   rI   r9   ry   rP   rO   timer   failr   rF   rQ   rS   rR   rT   )r>   rL   stop_atrV   s       rB   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)Nrv   )intervald           r   )	r9   r:   cpu_percentrangeassertIsInstancefloatassertGreaterEqualrI   r   )r>   rL   _percents       rB   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+   rd   r9   r:   r   called)r>   ms     rB   test_cpu_percent_numcpus_nonez)TestProcess.test_cpu_percent_numcpus_none   sF    ZZ*> 	!NN((*88O8	 	 	s   1AAzQEMU user not supportedc           
         t        j                         j                         }|j                  dk\  sJ |       |j                  dk\  sJ |       |j
                  dk\  sJ |       |j                  dk\  sJ |       t        r|j                  dk\  sJ |       |j                  D ]5  }t        j                  dt        j                  t        ||                   7 y )Nr   z%H:%M:%S)r9   r:   	cpu_timesusersystemchildren_userchildren_systemr   iowait_fieldsr   strftime	localtimegetattr)r>   timesr   s      rB   test_cpu_timeszTestProcess.test_cpu_times  s     **,zzS '%' ||s")E)"""c)050)$$+2U2+<<3&--&MM 	LDMM*dnnWUD5I&JK	LrX   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: )r9   r:   r   rG   r   maxminr   )r>   	user_timekernel_timeutimektimes        rB   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rX   znot supportedc                 8   t        j                         }|j                         }| j                  |d       t        j                         dk(  r| j                  |d       | j                  |j                         t        t        j                                      y Nr   ro   )r9   r:   cpu_numr   	cpu_countrF   assertInr   )r>   rL   nums      rB   test_cpu_numzTestProcess.test_cpu_num  sl    NNiikQ'"S!$aiik5)9)9);#<=rX   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)rC   r   create_timeabsr   r   r   )r>   rL   nowr   
differences        rB   test_create_timezTestProcess.test_create_time%  s{    iikmmo
 s*+
>))Z1  	)4>>!--/+JKrX   z
POSIX onlyc                     t        j                         j                         }|;t        j                  j                  t        d            }| j                  ||       y y )Ntty)r9   r:   terminalrG   pathrealpathr0   rF   )r>   r   r   s      rB   test_terminalzTestProcess.test_terminal7  sJ    >>#,,.''""2e9-CXs+  rX   )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   )r9   r:   io_countersopenr"   readr   r   assertGreater
read_countrF   write_countr   
read_charswrite_charsr   
read_byteswrite_bytes
get_testfnr   writebytesr   len)r>   rL   io1fio2is         rB   test_io_counterszTestProcess.test_io_counters>  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   )r9   IOPRIO_CLASS_NONEionice)initioclassvaluerL   s      rB   cleanupz.TestProcess.test_ionice_linux.<locals>.cleanupl  s-    !NGU&222HHWe$rX   r   ro   r         r      zioclass accepts no valuez$'ioclass' argument must be specified)r9   r:   r   rF   r   r   IOPRIO_CLASS_RTIOPRIO_CLASS_BEIOPRIO_CLASS_IDLE
addCleanuptuplerI   r   ri   assertRaisesRegex)r>   r   r   rL   s      @rB   test_ionice_linuxzTestProcess.test_ionice_linuxi  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 Windowsro   r   zis not a valid priority)r9   r:   r   rF   r   IOPRIO_NORMALr   IOPRIO_VERYLOW
IOPRIO_LOWIOPRIO_HIGHri   r   	TypeErrorr   )r>   rL   r   s      rB   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   ro   )resourcer9   r:   rG   rH   dir
startswithr   r   rF   r!   rlimit	getrlimitr   )r>   r  rL   r   namesr   r   rets           rB   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)rp   rp   zcan't use prlimitr   )rp   rp   rp   )rC   r  r9   RLIMIT_NOFILErF   r   r   r   _psplatformr:   rI   rK   s     rB   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   )r9   r:   r   r  RLIMIT_FSIZEr   r   rI   IOErrorrF   r   	exceptionrf   EFBIG)r>   rL   testfnsofthardr   excs          rB   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)	r9   r:   r  r  RLIM_INFINITYr   r   r   rF   )r>   rL   r  r  r   s        rB   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 r7   )r9   r:   r  r  rF   r  )r>   rL   r  r  s       rB   test_rlimit_infinity_valuez&TestProcess.test_rlimit_infinity_value  sV     NNXXf112
d--t4	$$tTl3rX   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 accessro   )	r9   r:   r	   num_threadsri   unittestSkipTestr&   rF   )r>   rL   step1step2s       rB   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   )r9   r:   r   num_handlesrK   s     rB   test_num_handleszTestProcess.test_num_handles  s&     NN1==?A.rX   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   ro   r   r   )r9   r:   r	   threadsri   r"  r#  r&   rF   r   idr   system_time)r>   rL   r$  r%  athreads        rB   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)rC   r	   r+  r9   ri   r"  r#  assertAlmostEqualr   r   sumr   r   r-  )r>   rL   r   s      rB   test_threads_2zTestProcess.test_threads_22  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` )r9   r:   memory_infomemory_percentr   r   r   rF   rsswsetvmspagefiler   r   )r>   rL   rss1vms1percent1memarrrss2vms2percent2memr   s              rB   test_memory_infozTestProcess.test_memory_infoG  s.   NN ]]_Ra(
d##%4#4# '!]]_Ra(
d##% 	4&d+8X.--/CSWWchh/SWWcll3mmoKK 	;D##GC$6:	;rX   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   )msgr:  )r9   r:   virtual_memorytotalmemory_full_infor   r   r   r
   r   assertLessEqualr   r   usspssswap)r>   rL   rH  rC  r   r   s         rB   test_memory_full_infoz!TestProcess.test_memory_full_infof  s    NN%%'--  "KK 	IDC&E##E14-#@u}  D%3G H	I Gu##CGGQ/##CGGQ/##CHHa0 rX   c                    t        j                         }|j                         }| j                  t	        |      t	        t        |                   |j                  d      }|D ]V  }|j                  j                  d      r t        rd|j                  v r5t        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HJ |j                          |D ][  }|j.                  D ]J  }t1        ||      }	|dk(  r|d	v r
|	rJ |	       | j3                  |	t4        t6        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
/bin/qemu-z/proc/self/smapsz%s (deleted)64r   )addrpermsr   )r9   r:   memory_mapsrF   r   setr   r  r$   rG   isabsr   existsislinkAssertionErrorr   r   r   basenamestatS_ISREGst_moder   r   r   r   intr   )
r>   rL   mapsext_mapsntr   datastfnamer   s
             rB   test_memory_mapszTestProcess.test_memory_mapsv  s!   NN}}TCD	N3===/ 	EB77%%c*!8ww}}RWW-6rww6-&!ww~~bgg6"''..GG; #77#    277#3#3BGG#<<E!#!1B $(<<

#;DRWWD#;;	E<  		-B -E*F?-- '%'5))%#t= A:,u,:-		-) * &$! "++=!> 0!'(vvx0 0 0-7tC %  D&   1 ! !s=   A#H!.I;!I8<I	I8II87I8;	JJ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 r7   )rG   r   r   normcase)rL   s    rB   normpathz8TestProcess.test_memory_maps_lists_lib.<locals>.normpath  s&    ww''(8(8(;<<rX   )r9   r:   r(   rU  r   r   )r>   rL   r   rj  r   libpathss         rB   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?!?)memtyperK  )r9   r:   r7  rI   r   r   r   r   rK   s     rB   test_memory_percentzTestProcess.test_memory_percent  sR    NN	*a&6&6FEWU+ %rX   c                     | j                         }|j                         sJ |j                         sJ |j                          |j                          |j                         rJ |j                         rJ y r7   )rC   
is_runningrO   rP   rK   s     rB   test_is_runningzTestProcess.test_is_running  s^    ||~~||~~		<<>!!<<>!!>rX   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   .ro   ra   rl   zimport os; print('hey')hey)rC   exerF   r"   rZ  r   r   rG   r   ri  sysversion_inforeplacer0   )r>   rL   rv  ri  verouts         rB   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        r(|j                         g k(  rt	        j
                  d      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 t        rB| j                  dj                  |j                         dd        dj                  |             y | j                  dj                  |j                               dj                  |             y )Nrl   2import time; [time.sleep(0.1) for x in range(100)]OPENBSD: returned EBUSYr    ro   r   )r"   rC   r   cmdliner"  r#  r	   r   rF   r   r   joinr$   )r>   r  rL   pyexes       rB   test_cmdlinezTestProcess.test_cmdline  s   @

 g&aiikR'##$=>> WQYY[^Z8		AJ&$$QR1388GABK3H   !))+ab/!:CHHW<MNSXXaiik2CHHW4EFrX   zbroken on PYPYc                    t         g}|j                  dgdz         |j                  ddg       | j                  |      }t        r"	 | j	                  |j                         |       y t        r$| j	                  |j                         dd  |       y |j                         }t        r|g k(  rt        j                  d      | j	                  ||       y # t        j                  $ r t        j                  d      w xY w)Nz-v2   rl   r~  z#OPENBSD: process turned into zombier   r  )r"   extendrC   r	   rF   r  r9   ZombieProcessr"  r#  r$   r   )r>   r  rL   r	  s       rB   test_long_cmdlinezTestProcess.test_long_cmdline   s    ,v{#GH	
 g&O  g6 QYY[_g6))+C#)''(ABBS'* '' O''(MNNOs    C )C?c                 D   | j                         }|j                         j                         }t        j                  j                  t        j                  j                  t        j                              j                         }|j                  |      s	J ||f       y r7   )
rC   r   lowerrG   r   r[  r   rw  
executabler  )r>   rL   r   r  s       rB   	test_namezTestProcess.test_name  so    vvx~~  !1!1#..!ABHHJ%4t}4%rX   zunreliable on PYPYzunreliable on QEMU userc                 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suffixrl   r~  )r*   r   rC   r	   rF   r   rG   r   r[  rZ  statusr9   STATUS_ZOMBIEr  r>   r  r  rL   s       rB   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 AIXzbroken on QEMU userc                    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  rl   r~  )r*   r   rC   rF   r  r   rG   r   r[  ri  rv  r  s       rB   test_prog_w_funky_namez"TestProcess.test_prog_w_funky_name;  s     doo[oAB@

 g&g.277#3#3E#:;))!%%'2BGG4D4DU4KLrX   c                 j   t        j                         }|j                         \  }}}| j                  |t	        j
                                | j                  |t	        j                                t        t        d      r3| j                  t	        j                         |j                                y y N	getresuid)	r9   r:   uidsrF   rG   getuidgeteuidhasattrr  r>   rL   real	effective_saveds        rB   	test_uidszTestProcess.test_uidsN  y    NN"#&&(iryy{+BJJL1 2{#R\\^QVVX6 $rX   c                 j   t        j                         }|j                         \  }}}| j                  |t	        j
                                | j                  |t	        j                                t        t        d      r3| j                  t	        j                         |j                                y y r  )	r9   r:   gidsrF   rG   getgidgetegidr  	getresgidr  s        rB   	test_gidszTestProcess.test_gids\  r  rX   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r7   )nicer9   ri   )r   rL   s    rB   r   z&TestProcess.test_nice.<locals>.cleanupk  s+    t&& s    ++str)priogetpriorityro   r   )r9   r:   rI   r   r  r   r   IDLE_PRIORITY_CLASSBELOW_NORMAL_PRIORITY_CLASSNORMAL_PRIORITY_CLASSABOVE_NORMAL_PRIORITY_CLASSHIGH_PRIORITY_CLASSREALTIME_PRIORITY_CLASSsubTestrF   ri   r  rG   r  PRIO_PROCESSrH   r   )r>   r   r   highest_prior  new_priorL   s         @rB   	test_nicezTestProcess.test_nicej  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 r7   )r9   r:   rF   r  STATUS_RUNNINGrK   s     rB   test_statuszTestProcess.test_status  s*    NNV%:%:;rX   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)rC   usernamer   splitgetpassgetuserendswithr"  r#  rF   rG   environ)r>   rL   r  domaingetpass_users        rB   test_usernamezTestProcess.test_username  s    ::<'~~d3FH"??,L$$S) ''(DEEX|4rzz)  L)AB * Xw'89rX   c                     | j                         }| j                  |j                         t        j                                y r7   )rC   rF   cwdrG   getcwdrK   s     rB   test_cwdzTestProcess.test_cwd  s,    "))+.rX   c                 d    t         ddg}| j                  |      }t        |j                  d       y )Nrl   zFimport os, time; os.chdir('..'); [time.sleep(0.1) for x in range(100)]z#ret == os.path.dirname(os.getcwd()))r"   rC   r'   r  )r>   rs   rL   s      rB   
test_cwd_2zTestProcess.test_cwd_2  s5    	
 c"155?@rX   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   ro   )r9   r:   cpu_affinityr   r  rG   rF   listr  r;   r   rV  r   r   r  r   _proc_get_eligible_cpusrI   r   r   )r>   rL   initialall_cpusns        rB   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'rX   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   )	rC   r   r9   r   rI   r   r  r   r   )r>   rL   invalid_cpus      rB   test_cpu_affinity_errsz"TestProcess.test_cpu_affinity_errs  s    6++489B>?*annkB*anneE56IJ)Q^^aX>*annq"g>rX   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   ro   )r9   r:   r  r   r   r   	itertoolscombinationsappendr  rF   sorted)r>   rL   r  combosr   subsetcombos          rB   "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rX   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  zIimport time; f = open(r'%s', 'r'); [time.sleep(0.1) for x in range(100)];rl   r   r   )r9   r:   r   
open_filesassertNotInr   r   flushr'   r   rG   r   ri  r   r   rF   positionisfilerC   r"   r   r   sleep)	r>   rL   r  filesr   r   	filenamesfiler  s	            rB   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
$% 	 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   ro   )r9   r:   rG   r   ri  r   r   r  r   fdfilenor   reprrF   r   r  )r>   rL   ri  r  fileobjr  ntuples          rB   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  ro   r   )	r9   r:   r   num_fdsr   r   closerF   socket)r>   rL   r  startr  socks         rB   test_num_fdszTestProcess.test_num_fds^  s    NN"		FC 

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

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



e,rX   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)r9   r:   r3  num_ctx_switchesr   r   r  r   )r>   rL   beforer   afters        rB   test_num_ctx_switchesz!TestProcess.test_num_ctx_switchesm  sq     NNQ'')*q 	AJJt**,-Ev~		
 iiLMMrX   c                 4   t        j                         }t        t        d      r2| j	                  |j                         t        j                                | j                         }| j	                  |j                         t        j                                y )Ngetppid)	r9   r:   r  rG   rF   ppidr  rC   rH   rK   s     rB   	test_ppidzTestProcess.test_ppidy  s^    NN2y!QVVXrzz|4299;/rX   c                 .   | j                         }| j                  |j                         j                  t	        j
                                t        j                         d   }| j                  t        j                  |      j                                y r   )
rC   rF   parentr;   rG   rH   r9   pidsassertIsNoner:   )r>   rL   
lowest_pids      rB   test_parentzTestProcess.test_parent  s`    5[[]1%
&..4;;=>rX   c                     t        j                         }| j                         \  }}| j                  |j	                         |       | j                  |j	                         |       y r7   )r9   r:   r   rF   r  r>   r  r   r   s       rB   test_parent_multizTestProcess.test_parent_multi  sP    ! 446z**,e40rX   c                 H   t        j                         }|j                         sJ | j                         \  }}| j	                  |j                         d   |       | j	                  |j                         d   |       | j	                  |j                         d   |       y r   )r9   r:   parentsr   rF   r  s       rB   test_parentszTestProcess.test_parents  s     !~~ 446z+V4++-a0%8++-a0&9rX   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   )creationflagsro   )r9   r:   rF   childrenrC   r   r;   r  )r>   r  r   	children1	children2r!  s         rB   test_childrenzTestProcess.test_children  s    !*B/48"= !!!2OO%	OOdO3	"I. 	=HS]A.Xa[__eii8Xa[--/<	=rX   c                 `   t        j                         }| j                         \  }}| j                  |j	                         |g       | j                  |j	                  d      ||g       |j                          |j                          | j                  |j	                  d      g        y )NTr  )r9   r:   r   rF   r!  rZ   rP   r  s       rB   test_children_recursivez#TestProcess.test_children_recursive  s     ! 446z*UG4485*:MN 	

48"=rX   c                 2   t        j                  t              }t        j                         D ]  }	 ||j                         xx   dz  cc<     t        |j                         d       d   d   }t        r|dk(  rt        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)	Nro   c                     | d   S )Nro    )r   s    rB   <lambda>z6TestProcess.test_children_duplicates.<locals>.<lambda>  s
    !A$ rX   )keyr   r   zPID 0Tr  )collectionsdefaultdictr_  r9   process_iterr  Errorr  itemsr   r"  r#  r:   r!  rF   r   rV  ri   )r>   tablerL   r;   cs        rB   test_children_duplicatesz$TestProcess.test_children_duplicates  s    '',$$& 	Aaffh1$	 U[[]7;A>SAX##G,,NN3	2

T
*A SVSQ[1 <<  "" 		s#   C''D  'C=<C= 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   ro   )r9   r:   r   r!  rF   r   r  )r>   r  r   r   r!  r  s         rB   test_parents_and_childrenz%TestProcess.test_parents_and_children  s    ! 446z??T?2X*!e,!j1$$&U+V,rX   c                 P   | j                         }|j                          t        d      D ]:  }|j                         t        j
                  k(  r nt        j                  d       < |j                          | j                  |j                         t        j
                         y )Nr   r   )
rC   r{   r   r  r9   STATUS_STOPPEDr   r  r|   assertNotEqual)r>   rL   r   s      rB   test_suspend_resumezTestProcess.test_suspend_resume  sv    			s 	AxxzV222JJt	 	

AHHJ(=(=>rX   c                     | j                  t        t        j                  d       | j                  t        t        j                  d       y )Nr  r   )rI   r   r9   r:   r   r>   s    rB   test_invalid_pidzTestProcess.test_invalid_pid  s.    )V^^S9*fnnb9rX   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)Nrv  r   )attrsnet_connectionsfoo)r>  ad_valuezpsutil.Process.niceT)createrc   r  ro   bar)r9   r:   as_dictrF   r  keysr   r  
isinstancer  r+   rd   ri   r<   r;   rI   r  NotImplementedErrorr  r   r   )r>   rL   ds      rB   test_as_dictzTestProcess.test_as_dict  s   NNIIUFOI,)E6?;NN3v{{}-.II./%I@!-.5Q0159 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_timesro   r   r9   r:   r+   rd   oneshotr   rF   
call_countr>   rL   r   s      rB   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)NrK  z(psutil._psplatform.Process.oneshot_enterro   r   rL  )r>   rL   m1m2r   s        rB   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r7   )r   r  r8  rM  rF   )r>   p1p2p1_ppidp2_ppids        rB   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)rv  r   z didn't raise NSP and returned z instead)r+  r!  )r   r   r9   r  r<   ri   r	   )funfun_namer	  r>   s      rB   assert_raises_nspzFTestProcess.test_halfway_terminated_process.<locals>.assert_raises_nspQ  s    e x?:iiEH#N  '' '' && x+EEs   , &A4A42A4z%s not in ret)rC   rZ   rP   r   r'   r9   r  r;   rT   r,   iterall)r>   r_  rL   nsr]  r   s   `     rB   test_halfway_terminated_processz+TestProcess.test_halfway_terminated_processI  s    	& 		v{{Oaee$;<q!q! 	)ICc4(	)rX   c                 L    | j                         \  }}| j                  |       y r7   )spawn_zombieassertProcessZombie)r>   _parentzombies      rB   test_zombie_processzTestProcess.test_zombie_processo  s"    ++-  (rX   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   rb   )r9   r:   r+   rd   r  rq  r   rO  s      rB   $test_zombie_process_is_running_w_excz0TestProcess.test_zombie_process_is_running_w_exct  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   rb   )	r9   r:   r+   rd   r  rF   r  r  r   rO  s      rB    test_zombie_process_status_w_excz,TestProcess.test_zombie_process_status_w_exc  sn     NNZZ/,,Q/
 	 QXXZ)=)=>88O8	 	 	s   =BBc                    t         rddlm} nddlm} | j                         }t	        j
                  |j                        }|j                  |j                         dz   f|_        t        t	        j                                | j                  |j                  t        j                         |j                         rJ t         |             5 }t        t	        j                                d d d        | j                  d|j                  z  j                                | j!                  |j                  t        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                  d	t1        |             | j                  d	t3        |             | j-                  t        j.                  ||j4                         | j-                  t        j.                  ||j6                         | j-                  t        j.                  ||j8                         | j-                  t        j.                  ||j:                         y # 1 sw Y   xY w# 1 sw Y   >xY w)
Nr   )StringIOr   z-refreshing Process instance for reused PID %sz4process no longer exists and its PID has been reusedF)clear_cache)r   zterminated + PID reused)r   ioro  r8   r9   r:   r;   r   _identr  r.  r   _pmaprq  r   getvaluer  r,   r`  setterskillersr  r   r<   r  r  r  r  r  r!  )	r>   ro  subprL   r   rF  rb  r]  r   s	            rB   test_reused_pidzTestProcess.test_reused_pid  s!   #)""$NN488$EE1==?S01V  "#aeeV\\*<<>!! XZ( 	(A$$&'	(;aeeCJJL	
 	-FNN488,,,,Dq!bjj!8eL 	GIC4( G&&v';';S#FG G	G 	/Q8/a9v33S!&&Av33S!((Cv33S!))Dv33S!**E+	( 	(G Gs   K "KKK&	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   ro   )r  r  r  zNT AUTHORITY\SYSTEMrootr   )r9   r  rI   r<   r:   
pid_existsrF   r  r   ri   r   rP   rZ   r{   r|   rO   r]   rQ   rR   r,   r`  gettersru  r  r  r	   r   )r>   rL   r  rb  r]  r   r	  r   s           rB   
test_pid_0zTestProcess.test_pid_0  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ra   
)popr   dictr0  ry  )rH  kvs      rB   
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
)	maxDiffr9   r:   r  rG   copyr
   r   rF   )r>   r  rL   d1d2s        rB   test_environzTestProcess.test_environ  s]    	  NN		$

)*~R$ &srX   z<macOS 11+ can't get another process environment, issue #2084z(sometimes fails on `assert is_running()`c                    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)stdinrn   rX   r  3)ACr   )textwrapdedentr)   r   r8   rq   rr   r9   r:   r;   r3   rq  rF   rn   r   r   r   r  ri   communicate
returncode)r>   rV   cexerA   rL   envs         rB   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)l__name__
__module____qualname____doc__rC   rM   rW   r[   r_   r"  skipIfr   rj   rt   r   r}   r   r   r   r   r   r$   r   r   r   r   r   r   r   r2   r   r   r   r   r   r   r   r
  r  r  r  r  r&  r)  r   r/  r/   r1   r   r4  rD  rN  r   rf  rl  ro  rr  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&  r3  r5  r9  r<  rI  rP  rT  rZ  rc  ri  rk  rm  rx  r}  r   r  r    r  r)  rX   rB   r5   r5   O   s   )""	" X__Y,G -G"6 X__V./7 07*8*2"&	' X__Y 9:
L ;
L X__Y 9:N ;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__(/:-- ;--^ X__(/:	4 ;	4," X__Y 9:% ;%:G@ X__T+,+ -+.5 X__T&Y(<=X__Y 9:@ ; >@6 X__U-.X__S/*X__T+,X__Y 56M 7 - + /M X__Y-7 .7 X__Y-7 .7=~ X__Y 9:< ;<:"/
A X__))?;'( <'(R X__))?;? <? X__))?;F <F( X__S/*X__X78". 9 +".J X__S/*X__X78; 9 +;8 X__Y-- .- U+X__W&(JKN L ,N0?1 X__Y 9::  ;:=>2(-?:5&n**(1$)L X__Y-) .) X__Y- . X__Y-	 .	&FP%(N X___o6% 7%0 X___o6X__Y-X__F X__VGH%. I	 . 7%.rX   r5   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r7   )r9   ri   )r>   meths    rB   test_z+LimitedUserTestCase.__init__.<locals>.test_;  s%    !.. s    !!)r   __init__r  r  r   setattrtypes
MethodType)r>   r?   r@   r   attrr  r  	__class__s         @rB   r  zLimitedUserTestCase.__init__4  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   setUprG   setegidseteuidr>   r  s    rB   r  zLimitedUserTestCase.setUpC  s&    GMMOJJtJJtrX   c                     t        j                  | j                         t        j                  | j                         t               j                          y r7   )rG   r  PROCESS_UIDr  PROCESS_GIDr   tearDownr  s    rB   r  zLimitedUserTestCase.tearDownH  s5    JJt''(JJt''(GrX   c                     	 t        j                         j                  d       | j                  d      # t         j                  $ r Y y w xY w)Nr   zexception not raised)r9   r:   r  r   ri   r;  s    rB   r  zLimitedUserTestCase.test_niceM  sH    8 %%b) ii 677 && s   #6 AAro   zcauses problem as rootc                      y r7   r)  r;  s    rB   ri  z'LimitedUserTestCase.test_zombie_processU  s    rX   )r  r  r  r  r  rG   r  r  r  r  r  r  r  r  r"  r  ri  __classcell__)r  s   @rB   r  r  )  se    	 2x #"))+K#"))+K	C	
	
	8 
4	5	 
6	rX   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 r7   r-   )clss    rB   tearDownClasszTestPopen.tearDownClassb  s    rX   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)Nrl   3import time; [time.sleep(0.1) for x in range(100)];stdoutrn   r  r@  rp   )r"   r9   Popenrq   rr   r#   r   r   r  
assertTruer  rI   rJ   r   rZ   r   rF   rP   rQ   rR   r>   rs   procs      rB   	test_misczTestPopen.test_miscf  s    
 A

 \\????	
 	
 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  rn   r  r  r   )r9   r  r"   rq   rr   r#   r  r  closedrn   r  rF   r  )r>   r  s     rB   test_ctx_managerzTestPopen.test_ctx_manager  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)Nrl   r  r  )r"   r9   r  rq   rr   r#   rZ   rP   rI   r<   rO   r]   rQ   rR   r   CTRL_C_EVENTCTRL_BREAK_EVENTr  s      rB   test_kill_terminatezTestPopen.test_kill_terminate  s   
 A

 \\????	
 	
 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)  rX   rB   r  r  _  s&    ' ;4-rX   r  __main__)run_from_name)Jr  r,  rf   r  r  rG   rQ   r  r\  rq   rw  r  r   r  r"  r9   r   r   r   r   r   r	   r
   r   r   r   psutil._commonr   psutil._compatr   r   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/   r0   r1   r2   r3   r5   r  r  r  r  psutil.tests.runnerr  __file__r)  rX   rB   <module>r     s   &     	     
                $  ,  *   ! # ' ' ) $ # ( ) - # $ %  # ' " ' # # , % &  * & )  . 0 %P.. P.p. 	YRYY[A.k .lM M` z1( rX   