Unix process tree search
Project description
pgtree
Unix process hierachy tree display for specific processes (kind of mixed pgrep + pstree)
pgtree is also able to send signal to found processes and all their children
The purpose is to have the tool working out of the box on any Unix box, using the default OS python installed, without installing anything else. The code must be compatible with python 2.x + 3.x
Should work on any Unix that can execute :
# /usr/bin/pgrep
# /usr/bin/ps ax -o pid,ppid,stime,user,ucomm,args
if pgrep
command not available (AIX), pgtree uses built-in pgrep (-f -i -x -u <user>
supported).
-T
option to display threads only works if ps ax -T -o spid,ppid
available on system (ubuntu/redhat...)
pgtree Tested on various versions of RedHat / CentOS / Ubuntu / Debian / Suse / FreeBSD / ArchLinux / MacOS / Solaris / AIX including old versions
(uses -o fname on Solaris)
Installation
FYI, the pgtree/pgtree.py
is standalone and can be directly copied/used anywhere without any installation.
installation using pip:
# pip install pgtree
Usage
# pgtree -h
usage: pgtree.py [-W] [-RIya] [-C <when>] [-O <psfield>] [-c|-k|-K] [-1|-p <pid1>,...|<pgrep args>]
-I : use -o uid instead of -o user for ps command
(if uid/user mapping is broken ps command can be stuck)
-c : display processes and children only
-k : kill -TERM processes and children
-K : kill -KILL processes and children
-y : do not ask for confirmation to kill
-R : force use of internal pgrep
-C : color preference : y/yes/always or n/no/never (default auto)
-w : tty wrap text : y/yes or n/no (default y)
-W : watch and follow process tree every 2s
-a : use ascii characters
-T : display threads (ps -T)
-O <psfield>[,psfield,...] : display multiple <psfield> instead of 'stime' in output
<psfield> must be valid with ps -o <psfield> command
by default display full process hierarchy (parents + children of selected processes)
-p <pids> : select processes pids to display hierarchy (default 0)
-1 : display hierachy children of pid 1 (not including pid 0)
<pgrep args> : use pgrep to select processes (see pgrep -h)
found pids are prefixed with ▶
Examples
show all parents and children of processes matching bash
show processes matching bash
and their children
kill all sh
processes of user joknarf and their children
Customize ps output fields:
Put default options in PGTREE env variable:
# export PGTREE='-1 -O %cpu,stime -C y'
# pgtree
Use watch utility to follow process tree:
# pgtree -W bash
Demo
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pgtree-1.1.1.tar.gz
.
File metadata
- Download URL: pgtree-1.1.1.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4c9fe7e291ebf1b562cef319e1a7826d8bd5425b682aadf8de15d58ef7cfe59 |
|
MD5 | 25879522927aa05cc8c329dd554077d0 |
|
BLAKE2b-256 | 47dba45e1e83c1e65c9115617a35695b0cffa660ec3f38c8ea406b4cc92ab93e |
File details
Details for the file pgtree-1.1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: pgtree-1.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5eb1ff9506a777389b31e9c76dd850c85df8d70e0159e051243cddcd34047bd3 |
|
MD5 | 89ad62ec8e3b1ea07cfbc9480220dbec |
|
BLAKE2b-256 | 6b616e432a0fc56450f0254537c1bf83fc42aaaf76316cbc9d215558cecf5fa8 |