{"record":{"id":"cb63f383f53b61b7","repo":"benfred/py-spy","slug":"failed-to-get-subprocesses","errorCode":null,"errorMessage":"failed to get subprocesses","messagePattern":"failed to get subprocesses","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/dump.rs","lineNumber":68,"sourceCode":"            out,\n            \"Parent Process {}: {}\",\n            style(parentpid).bold().yellow(),\n            parentprocess.cmdline()?.join(\" \")\n        )?;\n    }\n    writeln!(out)?;\n    let traces = process\n        .get_stack_traces()\n        .context(\"Failed to get stack traces\")?;\n    for trace in traces.iter().rev() {\n        write_trace(out, trace, true)?;\n    }\n\n    if config.subprocesses {\n        for (childpid, parentpid) in process\n            .process\n            .child_processes()\n            .expect(\"failed to get subprocesses\")\n        {\n            let term = Term::stdout();\n            let (_, width) = term.size();\n\n            writeln!(out, \"\\n{}\", &style(\"-\".repeat(width as usize)).dim())?;\n            // child_processes() returns the whole process tree, since we're recursing here\n            // though we could end up printing grandchild processes multiple times. Limit down\n            // to just once\n            if parentpid == pid {\n                write_traces(out, childpid, config, Some(parentpid))?;\n            }\n        }\n    }\n    Ok(())\n}\n\n#[cfg(target_os = \"linux\")]\npub fn print_trace(trace: &StackTrace, include_activity: bool) {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/benfred/py-spy/blob/32080cc0c22bc23938541dfa7dabb6090e40be14/src/dump.rs#L50-L86","documentation":"With --subprocesses, py-spy enumerates the target's child processes via process.process.child_processes() in DumpData::write_traces. If the OS API for enumerating child processes fails, expect() panics with \"failed to get subprocesses\" instead of continuing with just the parent trace.","triggerScenarios":"Running `py-spy dump --pid <pid> --subprocesses` (or record with --subprocesses) when the child_processes() syscall fails — e.g. the target exited between opening it and enumeration, permission denied reading /proc entries, or a Windows API failure enumerating process tree.","commonSituations":"Profiling a short-lived parent that respawns/exits children rapidly, profiling processes owned by another user without elevated privileges, or containers where /proc child listings are restricted.","solutions":["Retry promptly after confirming the target process is still alive (the target may have exited mid-scan).","Run py-spy with elevated privileges (sudo on Linux/macOS, Administrator on Windows) so child process metadata is readable.","Drop --subprocesses and profile each pid individually if the process tree is unstable.","Profile the child directly instead of the parent when you know which worker you care about."],"exampleFix":"// before\npy-spy record --pid 1234 --subprocesses  # target died mid-scan: panic\n// after\nps -p 1234 && py-spy record --pid 1234 --subprocesses  # verify alive first; sudo if needed\nsudo py-spy record --pid 1234 --subprocesses","handlingStrategy":"retry","validationCode":"kill -0 \"$PID\" 2>/dev/null || { echo \"target $PID already exited\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"run py-spy; if it aborts with 'failed to get subprocesses', verify the target is alive and retry with elevated privileges:\nfor i in 1 2 3; do\n  sudo py-spy dump --pid \"$PID\" --subprocesses && break\n  sleep 1\ndone","preventionTips":["Confirm the target survives the scan window before using --subprocesses.","Run py-spy with sudo/Administrator when profiling other users' processes.","Profile individual child pids instead of the tree when children churn rapidly."],"tags":["process-enumeration","subprocesses","permissions","race-condition"],"backgroundTag":"process-enumeration-failed","analyzedSha":"32080cc0c22bc23938541dfa7dabb6090e40be14","analyzedAt":"2026-09-05T19:30:55.142Z","contentChangedAt":"2026-09-05T19:30:55.142Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}