Viewing File: /opt/hc_python/lib/python3.12/site-packages/psutil/__pycache__/_psposix.cpython-312.pyc

�

`�*j7-���dZddlZddlZddlZddlZddlZddlZddlZddlm	Z
ddlmZddlm
Z
ddlmZddlmZdd	lmZerdd
lmZgd�Zd�Zej(d
ej*D�cic]}|j,|j.��c}�Zd�Zd�Zdej6eedej�eej<efd�Zd�Z dd�Z!dd�Z"ed��Z#ed��Z$dd�Z%eje%_d�Z&ed��Z'ycc}w)z%Routines common to all posix systems.�N�)�_ntuples)�MACOS��TimeoutExpired)�debug)�memoize)�
usage_percent)�_psutil_osx)�
pid_exists�wait_pid�
disk_usage�get_terminal_mapc�p�|dk(ry	tj|d�y#t$rYyt$rYywxYw)z6Check whether pid exists in the current process table.rTF)�os�kill�ProcessLookupError�PermissionError)�pids �@/opt/hc_python/lib64/python3.12/site-packages/psutil/_psposix.pyrrsD��
�a�x��
�
����Q�����������s��	5�5�5�	Negsignalc�<�	t|�S#t$r|cYSwxYw)z+Convert a negative signal value to an enum.)r�
ValueError)�nums r�negsig_to_enumr8s%�����~������
��s�

��c���tj|�rtj|�Stj|�rt	tj
|��Sd|��}t
|��)z.Convert a os.waitpid() status to an exit code.zunknown process exit status )r�	WIFEXITED�WEXITSTATUS�WIFSIGNALEDr�WTERMSIGr)�status�msgs  r�convert_exit_coder#@s\��	�|�|�F���~�~�f�%�%�	�~�~�f���r�{�{�6�2�2�3�3�"
)��
�
3�C�
�S�/���	monotonicc�4������
�d}d�d}d�
��"|tjz}�dk7r
���z�
�����
�fd�}			tj||�\}
}|
dk(r	|	|�}nt|�S�4#t$r||�r|	|�}||�r�YywxYw)a�Wait for a process PID to terminate.

    If the process terminated normally by calling exit(3) or _exit(2),
    or by returning from main(), the return value is the positive integer
    passed to *exit().

    If it was terminated by a signal it returns the negated value of the
    signal which caused the termination (e.g. -SIGTERM).

    If PID is not a children of os.getpid() (current process) just
    wait until the process disappears and return None.

    If PID does not exist at all return None immediately.

    If timeout is specified and process is still alive raise
    TimeoutExpired.

    If timeout=0 either return immediately or raise TimeoutExpired
    (non-blocking).
    g-C��6?g{�G�z�?rNc�d���dk(s�����k\rt����|��|dz��S)Nr�r)�interval�_min�_sleep�_timer�max_interval�stop_at�timeouts ������r�sleep_or_timeoutz(wait_pid_posix.<locals>.sleep_or_timeout�s<����a�<�G�/�F�H��4G� ��)�)��x���H�q�L�,�/�/r$)r�WNOHANG�waitpidr#�ChildProcessError)rr/�_waitpidr,r*r+�_pid_existsr)�flagsr0�retpidr!r-r.s ` ```      @@r�wait_pid_posixr8_s����:�H��L�
�E��G���
�������a�<��h��(�G�0�0��	1��Z�Z��U�3�N�F�F���{�+�H�5��(��0�0�%��!�		��c�"�+�H�5���c�"��		�s�A2�2!B�Bc��	tj|d�\}}|dk7sJ�t|�S#t$rt	||�cYSwxYw)zhWrapper around os.waitpid(). PID is supposed to be gone already,
    it just returns the exit code.
    r)rr2r#r3r8)rr/r7r!s    rr4r4�sR��)����C��+����
��{��{� ��(�(���,��c�7�+�+�,�s�-�A�Ac��	tj|d�}	tj�}|j|tj�|�dn
t|dz�}|j|�}|st|��t!||�tj"|�S#t$r�}|jtjk(rt||�cYd}~S|jtjtjtjhvr td|�d��t||�cYd}~S�d}~wwxYw#tj"|�wxYw)zbWait for PID to terminate using pidfd_open() + poll(). Linux >=
    5.3 + Python >= 3.9 only.
    rNzpidfd_open() failed (�); use fallbacki�)r�
pidfd_open�OSError�errno�ESRCHr8�EMFILE�ENFILE�ENODEVr�select�poll�register�POLLIN�intrr4�close)rr/�pidfd�err�poller�
timeout_ms�eventss       r�wait_pid_pidfd_openrN�s����
�
�c�1�%���
���������v�}�}�-�$�_�T�#�g��n�2E�
����Z�(��� ��)�)���W�%�
������5�
��9�9����#�"�#�w�/�/��9�9����u�|�|�U�\�\�B�B�
�)�#���@�A�!�#�w�/�/�
��
��4	�����s<�B�A/D9�	D6�'(D1�D6�AD1�*D6�0D1�1D6�9Ec�2�	tj�}	tj|tjtjtjztj��}	|j|gd|�}|st|��t||�|j!�S#t$rR}|jtjtj
hvr t
d|�d��t||�cYd}~S�d}~wwxYw#t$rq}|jtj"tj$tj&hvr0t
d|�d��t||�cYd}~|j!�S�d}~wwxYw#|j!�wxYw)z=Wait for PID to terminate using kqueue(). macOS and BSD only.zkqueue() failed (r;N��filterr6�fflagsrzkqueue.control() failed ()rC�kqueuer=r>r@rArr8�kevent�KQ_FILTER_PROC�	KQ_EV_ADD�
KQ_EV_ONESHOT�KQ_NOTE_EXIT�controlrr4rH�EACCES�EPERMr?)rr/�kqrJ�kevrMs      r�wait_pid_kqueuer^�sB���
�]�]�_����m�m���(�(��"�"�V�%9�%9�9��&�&�	
��
	*��Z�Z���q�'�2�F��$�W�-�-��C��)�
���
��3���9�9����u�|�|�4�4��%�c�W�O�<�=�!�#�w�/�/�
��	���	��y�y�U�\�\�5�;�;����D�D��1�#���H�I�%�c�7�3�3�	���
�

��		��	���
�sg�B)�AF�,D�F�)	D�2AC?�8D�>C?�?D�	F�AE<�%F�&F�;E<�<F�F�Fc�0�ttd�sy	tjtj�d�}tj|�y#t
$r;}|jtjtjhvrYd}~yYd}~yd}~wwxYw)Nr<FrT)	�hasattrrr<�getpidrHr=r>r@rA)rIrJs  r�can_use_pidfd_openrb�so���2�|�$����
�
�b�i�i�k�1�-��	����������9�9����u�|�|�4�4����
�s�(A�	B�,B�Bc��d}td�|D��syd}	tj�}tjt	j
�tjtjtjztj��}|j|gdd�	|�|j�yy#t$ra}|jtjtjhvrYd}~|�|j�yyYd}~|�|j�yyd}~wwxYw#|�|j�wwxYw)N)rSrVrWrUrXc3�<K�|]}tt|����y�w�N)r`rC)�.0�xs  r�	<genexpr>z!can_use_kqueue.<locals>.<genexpr>s����1�5�a�w�v�q�!�5�s�FrPrrT)�allrCrSrTrrarUrVrWrXrYrHr=r>r@rA)�namesr\r]rJs    r�can_use_kqueuerks��
�E��1�5�1�1��	
�B��
�]�]�_���m�m��I�I�K��(�(��"�"�V�%9�%9�9��&�&�	
��	�
�
�C�5�!�Q����>��H�H�J���
���9�9����u�|�|�4�4���>��H�H�J���
�>��H�H�J���
���>��H�H�J��s0�BB<�<	D&�,D!�1D)�	D)�!D&�&D)�)D>c��|dkDsJ�|�|dk\sJ�t�rt||�St�rt||�St	||�S)Nr)rbrNrkr^r8)rr/s  rr
r
(sT����7�N�7����!�|��|���"�3��0�0�	�	��s�G�,�,��c�7�+�+r$c�\�tj|�}|j|jz}|j|jz}|j
|jz}||z
}trtj||�}||z}t||d��}tj||||��S)a.Return disk usage associated with path.
    Note: UNIX usually reserves 5% disk space which is not accessible
    by user. In this function "total" and "used" values reflect the
    total and used disk space whereas "free" and "percent" represent
    the "free" and "used percent" user disk space.
    r)�round_)�total�used�free�percent)r�statvfs�f_blocks�f_frsize�f_bfree�f_bavailrr�disk_usage_usedr
�ntp�
sdiskusage)�path�stro�
avail_to_root�
avail_to_userrp�
total_user�usage_percent_users        rrr:s���
���D�	�B�
�K�K�"�+�+�%�E��J�J����,�M��K�K�"�+�+�-�M��=� �D���*�*�4��6���
�%�J�'�t�Z��B��
�>�>��$�]�<N��r$c���i}tjd�tjd�z}|D]0}||vsJ|��	||tj|�j<�2|S#t$rY�@wxYw)zNGet a map of device-id -> path as a dict.
    Used by Process.terminal().
    z	/dev/tty*z
/dev/pts/*)�globr�stat�st_rdev�FileNotFoundError)�ret�ls�names   rrr^sx��

�C�	
���;�	�$�)�)�L�"9�	9�B����3��$��$��	�)-�C�����
�%�%�&���J��!�	��	�s�"A%�%	A1�0A1re)(�__doc__�enumr>r�rrC�signal�time�rry�_commonrrrr	r
r�__all__r�IntEnum�Signalsr��valuerrr#r2�getattr�min�sleepr8r4rNr^rbrkr
rr)rgs0r�<module>r�s'��
,����	�
�
����#���"���G���,
�D�L�L��F�N�N�;�N�q�!�&�&�1�7�7�(�"�N�;�
�	�
��B
�
�Z�Z��4��d�i�i�0�	��:�:��A1�H)� �F�@	��	��$	��	��@,�"�)�)���!�H	��	���W	<s�-D
Back to Directory File Manager