pgtree


Namepgtree JSON
Version 1.1.1 PyPI version JSON
download
home_pagehttps://github.com/joknarf/pgtree
SummaryUnix process tree search
upload_time2024-07-04 20:46:47
maintainerNone
docs_urlNone
authorjoknarf
requires_pythonNone
licenseMIT
keywords shell pstree pgrep process tree
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            [![Travis CI](https://app.travis-ci.com/joknarf/pgtree.svg?token=ERTmZfyqzDZTSfQwkAfa&branch=master)](https://travis-ci.com/github/joknarf/pgtree)
[![Codecov](https://codecov.io/github/joknarf/pgtree/coverage.svg?branch=master)](https://codecov.io/gh/joknarf/pgtree)
[![Upload Python Package](https://github.com/joknarf/pgtree/workflows/Upload%20Python%20Package/badge.svg)](https://github.com/joknarf/pgtree/actions?query=workflow%3A%22Upload+Python+Package%22)
[![Pypi version](https://img.shields.io/pypi/v/pgtree.svg)](https://pypi.org/project/pgtree/)
[![Downloads](https://pepy.tech/badge/pgtree)](https://pepy.tech/project/pgtree)
[![Python versions](https://img.shields.io/badge/python-2.3+%20|%203.x-blue.svg)](https://shields.io/)
[![Licence](https://img.shields.io/badge/licence-MIT-blue.svg)](https://shields.io/)


# 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`

<img alt="# pgtree bash" src="https://user-images.githubusercontent.com/10117818/91555007-7d69a900-e930-11ea-98a2-8d81b7fdf0d3.png" width="850px">

show processes matching `bash` and their children

<img alt="# pgtree -c bash" src="https://user-images.githubusercontent.com/10117818/91555156-c15cae00-e930-11ea-9479-7c9b2c7b249e.png" width="850px">

kill all `sh` processes of user joknarf and their children

<img alt="#pgtree -k -u joknarf -x sh" src="https://user-images.githubusercontent.com/10117818/91555424-48aa2180-e931-11ea-8f19-6054458aa79c.png" width="850px">

Customize ps output fields:

<img width="719" alt="image" src="https://user-images.githubusercontent.com/10117818/215278250-83440d9c-f1a1-4ac7-afa5-db4f1b1c6395.png">

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
```
![image](https://user-images.githubusercontent.com/10117818/215317322-7df4559c-ccf4-41f6-b008-55d1fc8f0bb7.png)

## Demo

<img alt="output" src="https://user-images.githubusercontent.com/10117818/91558307-64fc8d00-e936-11ea-85bc-08eae29a58ce.gif" width="850px">


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/joknarf/pgtree",
    "name": "pgtree",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "shell pstree pgrep process tree",
    "author": "joknarf",
    "author_email": "joknarf@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/47/db/a45e1e83c1e65c9115617a35695b0cffa660ec3f38c8ea406b4cc92ab93e/pgtree-1.1.1.tar.gz",
    "platform": null,
    "description": "[![Travis CI](https://app.travis-ci.com/joknarf/pgtree.svg?token=ERTmZfyqzDZTSfQwkAfa&branch=master)](https://travis-ci.com/github/joknarf/pgtree)\n[![Codecov](https://codecov.io/github/joknarf/pgtree/coverage.svg?branch=master)](https://codecov.io/gh/joknarf/pgtree)\n[![Upload Python Package](https://github.com/joknarf/pgtree/workflows/Upload%20Python%20Package/badge.svg)](https://github.com/joknarf/pgtree/actions?query=workflow%3A%22Upload+Python+Package%22)\n[![Pypi version](https://img.shields.io/pypi/v/pgtree.svg)](https://pypi.org/project/pgtree/)\n[![Downloads](https://pepy.tech/badge/pgtree)](https://pepy.tech/project/pgtree)\n[![Python versions](https://img.shields.io/badge/python-2.3+%20|%203.x-blue.svg)](https://shields.io/)\n[![Licence](https://img.shields.io/badge/licence-MIT-blue.svg)](https://shields.io/)\n\n\n# pgtree\nUnix process hierachy tree display for specific processes (kind of mixed pgrep + pstree)\n\npgtree is also able to send signal to found processes and all their children\n\nThe 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.\nThe code must be compatible with python 2.x + 3.x\n\nShould work on any Unix that can execute :\n```\n# /usr/bin/pgrep \n# /usr/bin/ps ax -o pid,ppid,stime,user,ucomm,args\n```\n\nif `pgrep` command not available (AIX), pgtree uses built-in pgrep (`-f -i -x -u <user>` supported).\n\n`-T` option to display threads only works if `ps ax -T -o spid,ppid` available on system (ubuntu/redhat...)\n\n_pgtree Tested on various versions of RedHat / CentOS / Ubuntu / Debian / Suse / FreeBSD / ArchLinux / MacOS / Solaris / AIX including old versions_\n\n_(uses -o fname on Solaris)_\n\n## Installation\nFYI, the `pgtree/pgtree.py` is standalone and can be directly copied/used anywhere without any installation.\n\ninstallation using pip:\n```\n# pip install pgtree\n```\n\n## Usage\n```\n# pgtree -h\n    usage: pgtree.py [-W] [-RIya] [-C <when>] [-O <psfield>] [-c|-k|-K] [-1|-p <pid1>,...|<pgrep args>]\n\n    -I : use -o uid instead of -o user for ps command\n         (if uid/user mapping is broken ps command can be stuck)\n    -c : display processes and children only \n    -k : kill -TERM processes and children\n    -K : kill -KILL processes and children\n    -y : do not ask for confirmation to kill\n    -R : force use of internal pgrep\n    -C : color preference : y/yes/always or n/no/never (default auto)\n    -w : tty wrap text : y/yes or n/no (default y)\n    -W : watch and follow process tree every 2s\n    -a : use ascii characters\n    -T : display threads (ps -T)\n    -O <psfield>[,psfield,...] : display multiple <psfield> instead of 'stime' in output\n                   <psfield> must be valid with ps -o <psfield> command\n\n    by default display full process hierarchy (parents + children of selected processes)\n\n    -p <pids> : select processes pids to display hierarchy (default 0)\n    -1 : display hierachy children of pid 1 (not including pid 0)\n    <pgrep args> : use pgrep to select processes (see pgrep -h)\n\n    found pids are prefixed with \u25b6\n```\n## Examples\nshow all parents and children of processes matching `bash`\n\n<img alt=\"# pgtree bash\" src=\"https://user-images.githubusercontent.com/10117818/91555007-7d69a900-e930-11ea-98a2-8d81b7fdf0d3.png\" width=\"850px\">\n\nshow processes matching `bash` and their children\n\n<img alt=\"# pgtree -c bash\" src=\"https://user-images.githubusercontent.com/10117818/91555156-c15cae00-e930-11ea-9479-7c9b2c7b249e.png\" width=\"850px\">\n\nkill all `sh` processes of user joknarf and their children\n\n<img alt=\"#pgtree -k -u joknarf -x sh\" src=\"https://user-images.githubusercontent.com/10117818/91555424-48aa2180-e931-11ea-8f19-6054458aa79c.png\" width=\"850px\">\n\nCustomize ps output fields:\n\n<img width=\"719\" alt=\"image\" src=\"https://user-images.githubusercontent.com/10117818/215278250-83440d9c-f1a1-4ac7-afa5-db4f1b1c6395.png\">\n\nPut default options in PGTREE env variable:\n```\n# export PGTREE='-1 -O %cpu,stime -C y'\n# pgtree\n```\n\nUse watch utility to follow process tree:\n```\n# pgtree -W bash\n```\n![image](https://user-images.githubusercontent.com/10117818/215317322-7df4559c-ccf4-41f6-b008-55d1fc8f0bb7.png)\n\n## Demo\n\n<img alt=\"output\" src=\"https://user-images.githubusercontent.com/10117818/91558307-64fc8d00-e936-11ea-85bc-08eae29a58ce.gif\" width=\"850px\">\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Unix process tree search",
    "version": "1.1.1",
    "project_urls": {
        "Homepage": "https://github.com/joknarf/pgtree"
    },
    "split_keywords": [
        "shell",
        "pstree",
        "pgrep",
        "process",
        "tree"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6b616e432a0fc56450f0254537c1bf83fc42aaaf76316cbc9d215558cecf5fa8",
                "md5": "89ad62ec8e3b1ea07cfbc9480220dbec",
                "sha256": "5eb1ff9506a777389b31e9c76dd850c85df8d70e0159e051243cddcd34047bd3"
            },
            "downloads": -1,
            "filename": "pgtree-1.1.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "89ad62ec8e3b1ea07cfbc9480220dbec",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 16204,
            "upload_time": "2024-07-04T20:46:46",
            "upload_time_iso_8601": "2024-07-04T20:46:46.251943Z",
            "url": "https://files.pythonhosted.org/packages/6b/61/6e432a0fc56450f0254537c1bf83fc42aaaf76316cbc9d215558cecf5fa8/pgtree-1.1.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "47dba45e1e83c1e65c9115617a35695b0cffa660ec3f38c8ea406b4cc92ab93e",
                "md5": "25879522927aa05cc8c329dd554077d0",
                "sha256": "b4c9fe7e291ebf1b562cef319e1a7826d8bd5425b682aadf8de15d58ef7cfe59"
            },
            "downloads": -1,
            "filename": "pgtree-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "25879522927aa05cc8c329dd554077d0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12273,
            "upload_time": "2024-07-04T20:46:47",
            "upload_time_iso_8601": "2024-07-04T20:46:47.365083Z",
            "url": "https://files.pythonhosted.org/packages/47/db/a45e1e83c1e65c9115617a35695b0cffa660ec3f38c8ea406b4cc92ab93e/pgtree-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-04 20:46:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "joknarf",
    "github_project": "pgtree",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pgtree"
}
        
Elapsed time: 1.53443s