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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
339dfea9f2b065969f5fc82c2c15ae716200d95cffe7a8f1110f3e5bd99abc29
|
|
| MD5 |
363b145b535e060b67044dff05710570
|
|
| BLAKE2b-256 |
bad247aa915dbf27e716108b963b9e5e9003cc35dbe12f34ad3eef45b6bfcfda
|
Provenance
The following attestation bundles were made for process_watchman-0.2.1.tar.gz:
Publisher:
publish.yml on ATTMOS/process-watchman
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
process_watchman-0.2.1.tar.gz -
Subject digest:
339dfea9f2b065969f5fc82c2c15ae716200d95cffe7a8f1110f3e5bd99abc29 - Sigstore transparency entry: 1018753709
- Sigstore integration time:
-
Permalink:
ATTMOS/process-watchman@d6b9a4e3a427a60a79822bd086afd5c2f7f6f131 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/ATTMOS
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d6b9a4e3a427a60a79822bd086afd5c2f7f6f131 -
Trigger Event:
release
-
Statement type:
File details
Details for the file process_watchman-0.2.1-py3-none-any.whl.
File metadata
- Download URL: process_watchman-0.2.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
230aa45f838e0d7f5f072bdcf05d0bb6eb45237f46a80e99ecb01645e64b278f
|
|
| MD5 |
2e7d6ff271120b9004c7e381ffe89b16
|
|
| BLAKE2b-256 |
b22e2b4382f777e69317f202dd74cd540bad609231ff823f7ae11fe324d5d2b6
|
Provenance
The following attestation bundles were made for process_watchman-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on ATTMOS/process-watchman
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
process_watchman-0.2.1-py3-none-any.whl -
Subject digest:
230aa45f838e0d7f5f072bdcf05d0bb6eb45237f46a80e99ecb01645e64b278f - Sigstore transparency entry: 1018753720
- Sigstore integration time:
-
Permalink:
ATTMOS/process-watchman@d6b9a4e3a427a60a79822bd086afd5c2f7f6f131 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/ATTMOS
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d6b9a4e3a427a60a79822bd086afd5c2f7f6f131 -
Trigger Event:
release
-
Statement type: