#!/usr/bin/env bash # Scan for orphaned coding agent processes after a gateway restart. # # Background coding agents (Claude Code, Codex CLI) spawned by the gateway # can outlive the session that started them when the gateway restarts. # This script finds them and reports their state. # # Usage: # recover-orphaned-processes.sh # # Output: JSON object with `orphaned` array and `ts` timestamp.
set -euo pipefail
Scans for likely orphaned coding agent processes and prints JSON.
USAGE
}
if [ "${1:-}" = "--help" ] || [ "${1:-}" = "-h" ]; then
usage
exit 0 fi
if [ "$#" -gt 0 ]; then
usage >&2
exit 2 fi
if ! command -v node &>/dev/null; then
_ts="unknown"
command -v date &>/dev/null && _ts="$(date -u +%Y-%m-%dT%H:%M:%SZ 2>/dev/null)" || true
[ -z "$_ts" ] && _ts="unknown"
printf '{"error":"node not found on PATH","orphaned":[],"ts":"%s"}\n'"$_ts"
exit 0 fi
let lines; if (candidatePids.length > 0) {
// Fetch command info only for candidate PIDs.
lines = runFile("ps", ["-o", "pid=,command=", "-p", candidatePids.join(",")]).split("\n");
} elseif (pgrepUnavailable && username.length > 0) {
// pgrep not installed — fall back to user-scoped ps scan.
lines = runFile("ps", ["-U", username, "-o", "pid=,command="]).split("\n");
} elseif (pgrepUnavailable) {
// pgrep not installed and no username — full scan as last resort.
lines = runFile("ps", ["-axo", "pid=,command="]).split("\n");
} else {
// pgrep ran successfully but found no matches — no orphans.
lines = [];
}
for (const rawLine of lines) {
const line = rawLine.trim(); if (!line) {
continue;
}
const match = line.match(/^(\d+)\s+(.+)$/); if (!match) {
continue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.