HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //usr/share/doc/python3-psutil/examples/pidof.py
#!/usr/bin/env python3

# Copyright (c) 2009, Giampaolo Rodola', karthikrev. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.


"""A clone of 'pidof' cmdline utility.

$ pidof python
1140 1138 1136 1134 1133 1129 1127 1125 1121 1120 1119
"""

from __future__ import print_function

import sys

import psutil


def pidof(pgname):
    pids = []
    for proc in psutil.process_iter(['name', 'cmdline']):
        # search for matches in the process name and cmdline
        if (
            proc.info['name'] == pgname
            or proc.info['cmdline']
            and proc.info['cmdline'][0] == pgname
        ):
            pids.append(str(proc.pid))
    return pids


def main():
    if len(sys.argv) != 2:
        sys.exit('usage: %s pgname' % __file__)
    else:
        pgname = sys.argv[1]
    pids = pidof(pgname)
    if pids:
        print(" ".join(pids))


if __name__ == '__main__':
    main()