HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/ps.cpython-310.pyc
o

�N�g�I�@s�dZddlZddlZddlZddlZddlZddlmZm	Z	zddl
Z
dZWney1dZYnwdd�Z
dd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�ZdHdd�Zdd�ZdIdd�ZdJdd�ZdKdd �ZdLd!d"�ZdMd$d%�ZdNd&d'�Zd(d)�Zd*d+�ZdNd,d-�Zd.d/�ZdNd0d1�Z d2d3�Z!d4d5�Z"dId6d7�Z#dId8d9�Z$dId:d;�Z%d<d=�Z&d>d?�Z'ej(j)j*�+d@�dAd@��Z,ej(j)j*�+dB�dCdB��Z-dDdE�Z.dFdG�Z/dS)Oz�
A salt interface to psutil, a system and process library.
See http://code.google.com/p/psutil.

:depends:   - python-utmp package (optional)
�N)�CommandExecutionError�SaltInvocationErrorTFcCstsdSdS)N)FzCThe ps module cannot be loaded: python module psutil not installed.T)�
HAS_PSUTIL�rr�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/ps.py�__virtual__src	C�4z
tjj�|���WStjtjfygYSw)zq
    Returns the cmdline of a Process instance.

    It's backward compatible with < 2.0 versions of psutil.
    )�salt�utils�data�decodeZcmdline�psutil�
NoSuchProcess�AccessDenied��procrrr�_get_proc_cmdline!�
�rc	C�2z
tjj�|���WStjtjfyYdSw)zu
    Returns the create_time of a Process instance.

    It's backward compatible with < 2.0 versions of psutil.
    N)r	r
rr�create_timer
rrrrrr�_get_proc_create_time-�
�rc	Cr)zn
    Returns the name of a Process instance.

    It's backward compatible with < 2.0 versions of psutil.
    )r	r
rr�namer
rrrrrr�_get_proc_name9rrc	Cr)zp
    Returns the status of a Process instance.

    It's backward compatible with < 2.0 versions of psutil.
    N)r	r
rr�statusr
rrrrrr�_get_proc_statusErrc
Cs4z
tjj�|���WStjtjtfyYdSw)zr
    Returns the username of a Process instance.

    It's backward compatible with < 2.0 versions of psutil.
    N)	r	r
rr�usernamer
rr�KeyErrorrrrr�_get_proc_usernameQs
�rcCs|jS)zm
    Returns the pid of a Process instance.

    It's backward compatible with < 2.0 versions of psutil.
    )�pidrrrr�
_get_proc_pid]sr ��c	Cs�g}i}t��D]5}zt�|�}Wn
tjyYqwz|��dd�\}}Wntjy6d}}Ynw||||<qt�|�t�}|�	�D]*\}}	z|��dd�\}}Wn
tjydYqJw||}
|
|	}|�
||f�qJt|dd�dd�D]]\}}t|�p�t
|�t|�t|�t|�t|�iid�}z(|�����	�D]
\}
}||d	|
<q�|�����	�D]
\}
}||d
|
<q�Wn
tjy�Yq~w|�|�t|�|kr�|Sq~|S)a*
    Return a list of top CPU consuming processes during the interval.
    num_processes = return the top N CPU consuming processes
    interval = the number of seconds to sample CPU usage over

    CLI Examples:

    .. code-block:: bash

        salt '*' ps.top

        salt '*' ps.top 5 10
    N�gcSs|dS)Nrr)�xrrr�<lambda>�sztop.<locals>.<lambda>T)�key�reverse)�cmd�userrrr�cpu�memr*r+)r
�pids�Processr�	cpu_timesZ
ZombieProcess�time�sleep�set�items�add�sortedrrrrr r�_asdictZmemory_info�append�len)Z
num_processes�interval�resultZstart_usager�processr)�system�usage�start�now�diff�infor&�valuerrr�topfsb��
��	��
�rBcCst��S)z�
    Return a list of process ids (PIDs) for all running processes.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.get_pid_list
    )r
r,rrrr�get_pid_list�s
rCc
CsBzt�|�}|�|�WStjtjtfy }zt|��d}~ww)a�
    Return a dictionary of information for a process id (PID).

    CLI Example:

    .. code-block:: bash

        salt '*' ps.proc_info 2322
        salt '*' ps.proc_info 2322 attrs='["pid", "name"]'

    pid
        PID of process to query.

    attrs
        Optional list of desired process attributes.  The list of possible
        attributes can be found here:
        https://psutil.readthedocs.io/en/latest/#processes
    N)r
r-�as_dictrr�AttributeErrorr)rZattrsr�excrrr�	proc_info�s
��rG�cCs.zt�|��|�WdStjyYdSw)a�
    Kill a process by PID.

    .. code-block:: bash

        salt 'minion' ps.kill_pid pid [signal=signal_number]

    pid
        PID of process to kill.

    signal
        Signal to send to the process. See manpage entry for kill
        for possible values. Default: 15 (SIGTERM).

    **Example:**

    Send SIGKILL to process with PID 2000:

    .. code-block:: bash

        salt 'minion' ps.kill_pid 2000 signal=9
    TF)r
r-�send_signalr)r�signalrrr�kill_pid�s�rKc	Cs�g}t��D]<}|r|d�t|��vn|t|�v}|durdn|t|�k}|rB|rBz|�|�|�t|��Wqtj	yAYqwq|sGdSd|iS)a�
    Kill processes matching a pattern.

    .. code-block:: bash

        salt '*' ps.pkill pattern [user=username] [signal=signal_number] \
                [full=(true|false)]

    pattern
        Pattern to search for in the process list.

    user
        Limit matches to the given username. Default: All users.

    signal
        Signal to send to the process(es). See manpage entry for kill
        for possible values. Default: 15 (SIGTERM).

    full
        A boolean value indicating whether only the name of the command or
        the full command line should be matched against the pattern.

    **Examples:**

    Send SIGHUP to all httpd processes on all 'www' minions:

    .. code-block:: bash

        salt 'www.*' ps.pkill httpd signal=1

    Send SIGKILL to all bash processes owned by user 'tom':

    .. code-block:: bash

        salt '*' ps.pkill bash signal=9 user=tom
    � NT�killed)
r
�process_iter�joinrrrrIr6r r)�patternr)rJ�fullrMr�
name_match�
user_matchrrr�pkill�s$&�
�
��rTc	Cs�g}|rt�t|��}t��D]4}|rd�t|��}nt|�}|r(t�||�}n||v}|dur2dn|t	|�k}|rC|rC|�
t|��q|pGdS)a�
    Return the pids for processes matching a pattern.

    If full is true, the full command line is searched for a match,
    otherwise only the name of the command is searched.

    .. code-block:: bash

        salt '*' ps.pgrep pattern [user=username] [full=(true|false)]

    pattern
        Pattern to search for in the process list.

    user
        Limit matches to the given username. Default: All users.

    full
        A boolean value indicating whether only the name of the command or
        the full command line should be matched against the pattern.

    pattern_is_regex
        This flag enables ps.pgrep to mirror the regex search functionality
        found in the pgrep command line utility.

        .. versionadded:: 3001

    **Examples:**

    Find all httpd processes on all 'www' minions:

    .. code-block:: bash

        salt 'www.*' ps.pgrep httpd

    Find all bash processes owned by user 'tom':

    .. code-block:: bash

        salt '*' ps.pgrep bash user=tom
    rLNT)�re�compile�strr
rNrOrr�searchrr6r )	rPr)rQZpattern_is_regexZprocsrZprocess_linerRrSrrr�pgrep)s*�rY皙�����?cCs&|rtt�|d��}|St�|�}|S)aN
    Return the percent of time the CPU is busy.

    interval
        the number of seconds to sample CPU usage over
    per_cpu
        if True return an array of CPU percent busy for each CPU, otherwise
        aggregate all percents into one number

    CLI Example:

    .. code-block:: bash

        salt '*' ps.cpu_percent
    T)�listr
�cpu_percent)r8�per_cpur9rrrr\ks

�r\cCs2|rdd�t�d�D�}|Stt�|����}|S)aF
    Return the percent of time the CPU spends in each state,
    e.g. user, system, idle, nice, iowait, irq, softirq.

    per_cpu
        if True return an array of percents for each CPU, otherwise aggregate
        all percents into one number

    CLI Example:

    .. code-block:: bash

        salt '*' ps.cpu_times
    cS�g|]}t|����qSr��dictr5)�.0�timesrrr�
<listcomp>��zcpu_times.<locals>.<listcomp>T)r
r.r`r5)r]r9rrrr.�s
�r.cC�tt�����S)a
    .. versionadded:: 2014.7.0

    Return a dict that describes statistics about system memory usage.

    .. note::

        This function is only available in psutil version 0.6.0 and above.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.virtual_memory
    )r`r
�virtual_memoryr5rrrrrf��rfcCre)a
    .. versionadded:: 2014.7.0

    Return a dict that describes swap memory statistics.

    .. note::

        This function is only available in psutil version 0.6.0 and above.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.swap_memory
    )r`r
�swap_memoryr5rrrrrh�rgrhcCsdd�t�|�D�}|S)aK
    Return a list of disk partitions and their device, mount point, and
    filesystem type.

    all
        if set to False, only return local, physical partitions (hard disk,
        USB, CD/DVD partitions).  If True, return all filesystems.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.disk_partitions
    cSr^rr_)ra�	partitionrrrrc�rdz#disk_partitions.<locals>.<listcomp>)r
�disk_partitions)�allr9rrrrj�srjcCstt�|����S)z�
    Given a path, return a dict listing the total available space as well as
    the free space, and used space.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.disk_usage /home
    )r`r
�
disk_usager5)�pathrrrrl�srlcCs(t|�}|D]}|�t|d��q|S)z�
    Return a list of disk partitions plus the mount point, filesystem and usage
    statistics.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.disk_partition_usage
    Z
mountpoint)rj�updaterl)rkr9rirrr�disk_partition_usage�srocCs&zt��jWStytjYSw)z�
    Return the total number of bytes of physical memory.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.total_physical_memory
    )r
rf�totalrEZTOTAL_PHYMEMrrrr�total_physical_memory�s


�rqcCs$zt��WStytjYSw)zn
    Return the number of CPUs.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.num_cpus
    )r
�	cpu_countrEZNUM_CPUSrrrr�num_cpuss



�rsc
Csxztt���}Wntytt���}Ynw|r:tj�|�}z|�|�WSty9}ztd|����d}~ww|S)a�
    Return the boot time in number of seconds since the epoch began.

    CLI Example:

    time_format
        Optionally specify a `strftime`_ format string. Use
        ``time_format='%c'`` to get a nicely-formatted locale specific date and
        time (i.e. ``Fri May  2 19:08:32 2014``).

        .. _strftime: https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior

        .. versionadded:: 2014.1.4

    .. code-block:: bash

        salt '*' ps.boot_time
    zInvalid format string: N)	�intr
�	boot_timerE�datetime�
fromtimestamp�strftime�	TypeErrorr)�time_formatZb_timerFrrrrus���rucC�<|s
tt�����Stjdd�}||vrt||���SdS)z�
    Return network I/O statistics.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.network_io_counters

        salt '*' ps.network_io_counters interface=eth0
    T)ZpernicF)r`r
Znet_io_countersr5)Z	interface�statsrrr�network_io_counters7�r}cCr{)z�
    Return disk I/O statistics.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.disk_io_counters

        salt '*' ps.disk_io_counters device=sda1
    T)ZperdiskF)r`r
�disk_io_countersr5)Zdevicer|rrrrMr~rcCst��}dd�|D�S)zl
    Return logged-in users.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.get_users
    cSr^rr_)rar$rrrrcnrdzget_users.<locals>.<listcomp>)r
Zusers)Zrecsrrr�	get_userscs
r�cCs.t|�}tdd|�}g}|�||g�|S)z�
    Retrieve the lsof information of the given process name.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.lsof apache2
    �cmd.runzlsof -c )rW�__salt__�extend)r�
sanitize_nameZ
lsof_infos�retrrr�lsofqs

r��netstatcC�Tt|�}tdd�}g}g}|��D]}|�|�dkr |�|�q|�||g�|S)z�
    Retrieve the netstat information of the given process name.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.netstat apache2
    r�znetstat -nap����rWr��
splitlines�findr6r�)rr�Z
netstat_infos�found_infosr�r@rrrr��s
��sscCr�)z�
    Retrieve the ss information of the given process name.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.ss apache2

    .. versionadded:: 2016.11.6

    r�zss -neapr�r�)rr�Zss_infosr�r�r@rrrr��s
�cCs�t|�}t�|�}t�d�}tdd�}g}g}d}|��D]}|�|�}	|	dur7|�|�s7|d7}|�|�qt|�d}
g}|�|||
g�|S)a
    Retrieve information corresponding to a "ps aux" filtered
    with the given pattern. It could be just a name or a regular
    expression (using python search from "re" module).

    CLI Example:

    .. code-block:: bash

        salt '*' ps.psaux www-data.+apache2
    zsalt.+ps.psaux.+r�zps auxrN�z occurrence(s).)rWrUrVr�r�rXr6r�)rr�rPZsalt_exception_patternZps_auxr�r�Znb_linesr@�foundZ	pid_countrrr�psaux�s$




�r�c	sVg}�std��zt�gd��}�fdd�|D�}W|Stjtjfy*td��w)a8
    .. versionadded:: 3006.0

    Returns a list of processes according to their state.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.status STATUS

    where ``STATUS`` is one of

    * running
    * sleeping
    * disk_sleep
    * stopped
    * tracing_stop
    * zombie
    * dead
    * wake_kill
    * waking
    * parked (Linux)
    * idle (Linux, macOS, FreeBSD)
    * locked (FreeBSD)
    * waiting (FreeBSD)
    * suspended (NetBSD)

    See https://psutil.readthedocs.io/en/latest/index.html?highlight=status#process-status-constants

    z Filter is required for ps.status)rrrcs$g|]}|jd�kr|�d��qS)r)rr)r@rD)rar�rrrrc�s
�zstatus.<locals>.<listcomp>z)Psutil did not return a list of processes)rr
rNrrr)rr�Zlist_of_processesrr�rr�s!
���r)r!r")N)rH)NrHF)NFF)rZF)F)0�__doc__rvrUr/Zsalt.utils.datar	Zsalt.utils.decorators.pathZsalt.exceptionsrrr
r�ImportErrorrrrrrrr rBrCrGrKrTrYr\r.rfrhrjrlrorqrsrur}rr�r�r
Z
decoratorsrm�whichr�r�r�rrrrr�<module>s\�	
	D



:
B




#