Skip to main content

A small, focused Python library for tracking Linux process trees rooted at a specific PID.

Project description

process-watchman

process-watchman is a small, focused Python library for tracking Linux process trees rooted at a specific PID.

It answers questions like:

  • Which subprocesses are currently alive?
  • Which processes exited since the last poll?
  • Is the root process still valid (PID reuse safe)?
  • What is the current live descendant set?

Why process-watchman?

Workflow monitoring often fails because:

  • parent wrappers exit while compute children keep running
  • PIDs get reused
  • process discovery is unreliable across polling intervals

process-watchman solves this by:

  • tracking process identity as (pid + create_time)
  • maintaining a live descendant set
  • emitting clean deltas (added / removed processes)

Installation

pip install process-watchman

For development:

git clone https://github.com/ATTMOS/process-watchman.git
cd process-watchman
pip install -e ".[dev]"

Quick start

from process_watchman import ProcessTreeWatcher, WatcherConfig

# Attach to a running process by PID
watcher = ProcessTreeWatcher.attach(root_pid=12345)

# Poll the process tree
snapshot = watcher.poll()

print(f"Root alive: {snapshot.root_alive}")
print(f"Descendants: {len(snapshot.processes)}")
print(f"New PIDs: {snapshot.delta.added_pids}")

# Poll again later to see what changed
snapshot2 = watcher.poll()
print(f"Added: {snapshot2.delta.added_pids}")
print(f"Removed: {snapshot2.delta.removed_pids}")

# Get the current live set at any time
live = watcher.live_pids()

Configuration

Pass a WatcherConfig to customize behaviour:

from process_watchman import ProcessTreeWatcher, WatcherConfig

cfg = WatcherConfig(
    max_depth=8,              # limit tree traversal depth
    include_root=True,        # include the root process in results
    max_descendants=1000,     # cap collected descendants per poll
    strategy="scan_ppid",     # use BFS fallback instead of default
    capture_cmdline=True,     # collect command lines
    cmdline_max_chars=100,    # truncate long command lines
    keep_tombstones=True,     # retain info for removed processes
)

watcher = ProcessTreeWatcher.attach(root_pid=12345, config=cfg)

See docs/api.md for the full list of configuration options.


API overview

Type Description
ProcessTreeWatcher Main class — attach(), poll(), live_pids()
WatcherConfig Configuration with sensible defaults
Snapshot Point-in-time observation returned by poll()
Delta Changes between consecutive polls
ProcessIdentity PID + create_time (safe against PID reuse)
ProcessInfo Per-process metadata (name, cmdline, status)

Full API reference: docs/api.md


License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

process_watchman-0.2.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

process_watchman-0.2.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file process_watchman-0.2.0.tar.gz.

File metadata

  • Download URL: process_watchman-0.2.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for process_watchman-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f6b9bb67830e5ddff580a7cb0e93748488ae0cf4aa67c825bfeace2b67bc0b56
MD5 11350334a8f9c9e3e52f1f6ed17981f7
BLAKE2b-256 21652575c762096f59bfddcf948010954a5cbcdc13a8d34730816688537c631d

See more details on using hashes here.

File details

Details for the file process_watchman-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for process_watchman-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9da8f44e9ffef2ede533916c6dd534b3609949a9d4dcf243800a5903815c6cf
MD5 1a267218166fd09f1690020e587a12bb
BLAKE2b-256 a98b4d122ecdb1e3c5f6b9aaf577a53e474c21e7bca27ccc01aa328f1325e84e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page