Skip to main content

Travis CI Codecov Upload Python Package Pypi version Downloads Python versions Licence

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 -e -o pid,ppid,stime,user,ucomm,args

if pgrep command not available (AIX), pgtree uses built-in pgrep (-f -i -x -u <user> supported).

Tested on various versions of RedHat / CentOS / Ubuntu / Debian / Suse / MacOS / Solaris / AIX including old versions

(uses -o comm 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

installation using setup.py, root install in /usr/local/bin:

# ./setup.py install

installation using setup.py, user install in ~/.local/bin:

# ./setup.py install --prefix=~/.local

Usage

# pgtree -h
    usage: pgtree.py [-Iya] [-C <when>] [-O <psfield>] [-c|-k|-K] [-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
    -C : color preference : y/yes/always or n/no/never (default auto)
    -w : tty wrap text : y/yes or n/no (default y)
    -a : use ascii characters
    -O <psfield> : display <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 1)
    <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

# pgtree bash

show processes matching bash and their children

# pgtree -c bash

kill all sh processes of user joknarf and their children

#pgtree -k -u joknarf -x sh

Demo

output

Metadata

Release files for pgtree 1.0.19

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pgtree 1.0.19
File Size Uploaded
pgtree-1.0.19.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pgtree 1.0.19
File Interpreter ABI Platform
pgtree-1.0.19-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 22.3 kB

Release files / pgtree-1.0.19.tar.gz

Download URL pgtree-1.0.19.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a6211b88038f301760927f6ff1f88b4af9084deaa3dfd0b690e66b79c1b86f4c
BLAKE2b-256 checksum
How to use checksums
8248f6b06067e31b32c9e749904186d5cf65d1dbbe76f42f1107a7d7a3c236db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / pgtree-1.0.19-py2.py3-none-any.whl

Download URL pgtree-1.0.19-py2.py3-none-any.whl
Size 13.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
62cf9e85ebc0607c29b577b13f13e6f46fee82284efbac3c1a720c0c32814975
BLAKE2b-256 checksum
How to use checksums
047df12c33cf098e76ef5bb23e0b76d111fbc0a4a56c2aa87ad1d4601166d43c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

1.1.13

2 release files

1.1.11

2 release files

1.1.10

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.26

2 release files

1.0.25

2 release files

1.0.24

2 release files

1.0.23

2 release files

1.0.22

2 release files

1.0.21

2 release files

1.0.20

2 release files

This release

1.0.19 This release

2 release files

1.0.18

2 release files

1.0.17

2 release files

1.0.16

2 release files

1.0.15

2 release files

1.0.14

2 release files

1.0.13

2 release files

1.0.12

2 release files

1.0.11

2 release files

1.0.9

2 release files

1.0.8

1 release file

1.0.7

2 release files

1.0.6

1 release file

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page