Skip to content

Anuar-boop/process-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

process-tree

Cross-platform process tree viewer for the terminal. Displays process hierarchy with CPU/memory usage, supports filtering, searching, watch mode, JSON export, and zombie detection.

Features

  • Process tree display -- shows parent/child hierarchy like pstree
  • CPU & memory usage -- color-coded per process (green/yellow/red)
  • Filter by name, user, or PID -- shows matching processes with ancestors for context
  • Search processes -- grep through command lines
  • Highlight matches -- highlights search terms in the output
  • Thread count -- per-process thread info (Linux & macOS)
  • Sort -- by CPU, memory, PID, name, user, or thread count
  • Watch mode -- auto-refresh every N seconds
  • Kill process -- send signals to processes by PID
  • JSON export -- full tree as structured JSON
  • Environment variables -- inspect env vars for any PID
  • Zombie detection -- find and list zombie processes with their parents
  • Command arguments -- show full command or just binary name

Requirements

Python 3.7+ (uses only the standard library -- zero external dependencies). Works on Linux and macOS.

Usage

# Show full process tree
python process_tree.py

# Filter by process name
python process_tree.py -f python

# Filter by user
python process_tree.py -u root

# Show specific PID and its descendants
python process_tree.py -p 1234

# Search command lines
python process_tree.py -s "node server"

# Sort by CPU usage
python process_tree.py --sort cpu

# Sort by memory
python process_tree.py --sort mem

# Watch mode (refresh every 2 seconds)
python process_tree.py -w 2

# Watch mode with CPU sort (like htop tree view)
python process_tree.py -w 1 --sort cpu

# Export as JSON
python process_tree.py --json > processes.json

# Filter and export
python process_tree.py -f nginx --json

# Kill a process
python process_tree.py --kill 1234

# Kill with specific signal
python process_tree.py --kill 1234 --signal KILL

# Show environment variables for a PID
python process_tree.py --env 1234

# Detect zombie processes
python process_tree.py --zombies

# Hide command arguments (show only binary name)
python process_tree.py --no-args

# Highlight specific text
python process_tree.py --highlight python

# Disable colors (for piping)
python process_tree.py --no-color

Output Example

    PID USER        CPU    MEM  THR STAT  COMMAND
----------------------------------------------------------------------------------------------------
---     1 root         0.0%   0.3%    1 Ss    /sbin/init
    |--   456 root         0.1%   0.5%    3 Ss    /usr/lib/systemd/systemd-journald
    |--   789 root         0.0%   0.2%    1 Ss    /usr/sbin/sshd -D
    |   \-- 1234 user         0.0%   0.1%    1 Ss    sshd: user@pts/0
    |       \-- 1235 user         0.5%   0.3%    1 Ss    -bash
    |           \-- 5678 user        45.2%   2.1%   12 Sl    python train.py --epochs 100
    \--   999 root         0.0%   0.1%    1 Ss    /usr/sbin/cron

7 processes | Total CPU: 45.8% | Total MEM: 3.6%

Color Coding

Color Meaning
Green Low usage (< 10%)
Yellow Medium usage (10-50%)
Red High usage (> 50%)
Magenta Highlighted/matched text
Red + Bold Zombie process

CLI Options

usage: process_tree.py [-h] [-f NAME] [-u USER] [-p PID] [-s SEARCH]
                       [--sort {cpu,mem,pid,name,user,threads}] [-w SECONDS]
                       [--kill PID] [--signal SIGNAL] [--json] [--env PID]
                       [--zombies] [--no-args] [--no-color] [--highlight TEXT]

options:
  -f, --filter NAME    Filter processes by name
  -u, --user USER      Filter by user
  -p, --pid PID        Show specific PID and descendants
  -s, --search SEARCH  Search process commands
  --sort FIELD         Sort by: cpu, mem, pid, name, user, threads
  -w, --watch SEC      Watch mode: refresh every N seconds
  --kill PID           Kill process by PID
  --signal SIGNAL      Signal for --kill (default: TERM)
  --json               Export as JSON
  --env PID            Show environment variables for PID
  --zombies            Detect zombie processes
  --no-args            Hide command arguments
  --no-color           Disable color output
  --highlight TEXT     Highlight matching text

License

MIT

About

Cross-platform process tree viewer CLI. Filter, sort, watch, kill, export JSON, detect zombies. Zero dependencies.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages