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.1.tar.gz (12.3 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.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for process_watchman-0.2.1.tar.gz
Algorithm Hash digest
SHA256 339dfea9f2b065969f5fc82c2c15ae716200d95cffe7a8f1110f3e5bd99abc29
MD5 363b145b535e060b67044dff05710570
BLAKE2b-256 bad247aa915dbf27e716108b963b9e5e9003cc35dbe12f34ad3eef45b6bfcfda

See more details on using hashes here.

Provenance

The following attestation bundles were made for process_watchman-0.2.1.tar.gz:

Publisher: publish.yml on ATTMOS/process-watchman

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for process_watchman-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 230aa45f838e0d7f5f072bdcf05d0bb6eb45237f46a80e99ecb01645e64b278f
MD5 2e7d6ff271120b9004c7e381ffe89b16
BLAKE2b-256 b22e2b4382f777e69317f202dd74cd540bad609231ff823f7ae11fe324d5d2b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for process_watchman-0.2.1-py3-none-any.whl:

Publisher: publish.yml on ATTMOS/process-watchman

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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