witr: trace a port to its parent process

Something was holding port 9411 and the shell that started it had already exited. ss -lptn 'sport = :9411' answered in 42 ms with the pid, the user and the socket inode. Three of four questions. The fourth one, who launched this, needed a second tool, then a third, then a guess.
The exit is why the case is worth writing about. Linux reparents the orphan to PID 1, so /proc/<pid>/stat reports that its parent is systemd. Technically true. Useless in practice, because it describes adoption, not cause.
witr is built around that gap. It walks the chain from PID 1 down to the process and labels the break instead of papering over it. The four tools I reach for first each answer a different slice of the same question:
psandtopshow current state. No origin, no supervisor.ssandlsofshow who owns the socket right now.systemctl statusnames the unit that supervises a process, when a unit exists.witrgives the launch chain plus the service, container or session that owns it.
Step 1 – install witr v0.3.4 and check the binary
The install script fetches a single static binary and a man page. I pointed it at my home directory because the jump host I was on doesn’t hand out sudo for convenience tools.
curl -fsSL https://raw.githubusercontent.com/pranshuparmar/witr/main/install.sh \
| INSTALL_PREFIX="$HOME/.local" bash
witr --version
# witr v0.3.4 (commit 7e46fa6, built 2026-10-04T17:31:44Z)
The download was 7.7 MB and the installed binary is 7,905,464 bytes. No service account, nothing to daemonize, no config file to drift. On a host you don’t own, that is the difference between a tool you can run today and a ticket you file and forget.
Step 2 – trace a listening port to the process holding it
Same port, one command. This is the unedited output, minus the working directory line:
$ witr --port 9411
Target : python3
Process : python3 (pid 1168576)
User : hermes
Service : hermes-gateway.service
Command : python3 -m http.server 9411
Started : just now (Tue 2026-11-24 10:10:48 +00:00)
Why It Exists :
systemd (pid 1) → ? (original parent exited) → python3 (pid 1168576)
Source : hermes-gateway.service (systemd)
Description : Hermes Agent Gateway - Messaging Platform Integration
Unit File : /etc/systemd/system/hermes-gateway.service
Sockets : 0.0.0.0:9411 (TCP | LISTENING)
Warnings :
• Process is listening on a public interface
• Service name and process name do not match
Read it in three passes. Sockets says what is exposed and where: 0.0.0.0, not loopback, which is the first thing I want at 3 a.m. Why It Exists says the launcher is gone. Warnings says the process name doesn’t match the unit it lives under, which is the sort of mismatch that makes people delete the wrong service.
Then the part that bit me: exit code 1. The process was found, healthy, and listening. The tool returned non-zero because it had warnings. Any wrapper that treats non-zero as down will page you about a working web server, so check the code against the table in step 4 before you wire it into monitoring.
Step 3 – the ancestry break is the finding
? (original parent exited) is the most useful string in the output and the reason I kept the tool installed. It costs the program something to print it: instead of crediting systemd with parenting the process, it admits the chain is severed and names where. The JSON carries the same fact as ParentExited: true on the process object, so a script can branch on it without parsing sentences.
A tool that marks where the chain broke is worth more than one that fills the gap with the adopter. The break is the finding.
Two sections of the report disagree on purpose, and that took me a minute to read correctly. The chain says the parent exited. The Source section still names a systemd unit, because the cgroup outlived the shell that ran inside it. Both statements are true from different sources: one from the process table, one from the cgroup hierarchy. If the unit name surprises you, the process is running under a scope it doesn’t belong to, which is exactly the sort of leftover that keeps a closed socket open for days.
Step 4 – script it with –json and the exit codes
The exit codes are the real interface. They’re documented, stable, and they distinguish “not there” from “can’t see it” from “found, but nothing explains it”:
| Code | Meaning | What I do with it |
|---|---|---|
| 0 | Found, no warnings | Log and exit |
| 1 | Found with warnings | Log, do not alert |
| 2 | Not found | Nothing is running, skip |
| 3 | Permission denied | Retry with sudo, once |
| 4 | Bad input or ambiguous name | Re-run with --pid |
| 5 | Internal error | Report upstream |
| 6 | Found, cause unknown | Human reads the warnings |
On my box the JSON for that one process was 14,288 bytes. Most of it was the environment block, since --json includes Env by default, which is more than a status report needs when the only question is what launched the process. Select fields instead. Your log shipper will thank you.
witr --port 8080 --json | jq -r '.Ancestry[] | "\(.PID)\t\(.Command)"'
Do not adopt this for speed. The same query took 39 ms in witr, 42 ms in ss and 29 ms in lsof. It is one hop instead of four, not a faster hop, and the binary is 7.9 MB against lsof’s few hundred kilobytes. The win is the answer, not the millisecond.
Step 5 – hand it to an agent instead of four greps
Coding agents hit this constantly: a port in use, a dev server nobody remembers starting, a container that keeps respawning. Left alone they chain lsof, ps, netstat and docker ps and burn context on the joins. Three lines in AGENTS.md replace that:
Port in use: witr --port <PORT> --json
Stuck proc: witr <name> --json (or --pid <PID> --tree)
Container: witr --container <name> --json
Exit 1 means found with warnings, not failure.
The exit-code contract matters more for an agent than for me. An agent reads codes faster than prose, and it will retry a permission failure in a loop until something else stops it. Handing a shell tool to a model widens its reach too, the same way a loose allowlist leaked secrets to Claude Code; grant the specific subcommands you want and skip the rest. The output here is a report, not an action. That is the right shape for the growing pile of coding agents running on a workstation.
Where the causality stops
As a normal user, asking about a root-owned port returns exit 3 and the line socket found but owning process not detected; it belongs to root. ss at the same moment prints the socket with an empty process column. witr tells you less than you want and more than you’d have worked out unaided, which is the correct trade.
There is no history, and no tool in this family keeps one.
Two hours ago is a different question. If you need to know what held port 8080 back then, this cannot help. That belongs to auditd, an eBPF socket tracer, or a logging proxy in front of the port.
On macOS the backend shells out to ps, lsof, netstat and launchctl, so it inherits every limitation those tools carry, and System Integrity Protection blocks the environment for some system processes even under sudo. Windows takes the opposite shape, calling Win32 APIs directly, so there is no WMI stall. Launchers there exit routinely, though. An exited parent is not a finding on Windows, and exit 6 never fires.
The next test is a transient unit, started with systemd-run, where the owner is a scope rather than a service. If the chain holds across a scope that dies before the process does, the tool earns a permanent slot in my runbook. If it answers unknown, that still beats a plausible lie about PID 1. Cheap experiment either way.