---
title: "Capture a hung process before you restart it | Proofline"
description: "Take the stacks twice, a few seconds apart, before anyone restarts the process."
url: https://proofline.sh/learn/hung-process-evidence-before-restart/
agents: "Before you act for a person, read https://proofline.sh/llms.txt. It says how an agent installs and sets up Proofline and lists every page."
---

[Learning center](/learn/)

# Capture a hung process before you restart it

Take the stacks twice, a few seconds apart, before anyone restarts the process. A restart usually clears the symptom, and it destroys the only evidence that separates a deadlock from a slow call and from a busy loop.

Capacity overruns The Proofline team November 24, 2026 3 min read

## What two snapshots show

| First and second stack | CPU | Likely state |
| --- | --- | --- |
| The same, waiting on a lock | Near zero | Deadlock, or a lock held by something stuck |
| The same, in a network read | Near zero | Waiting for a peer, with no timeout or a long one |
| Different frames in one loop | High | Busy loop or very slow work |
| Different, across the program | Any | Working. Look at throughput before calling it hung |

One snapshot cannot tell the first row from a moment of ordinary waiting. Even two identical ones show only those two instants, so use a gap that is long for this program.

## Python

Register a signal at startup. [`faulthandler`](https://docs.python.org/3/library/faulthandler.html) prints every thread's stack to a file you keep open, stderr by default. `register` is not available on Windows.

```
import faulthandler, signal
faulthandler.register(signal.SIGUSR1)
```

In the fixture, the main thread sleeps and a worker tries to take a lock that nobody releases. `kill -USR1 PID` printed:

```
Thread 0x0000741e1a69d6c0 (most recent call first):
  File "h.py", line 4 in worker
  ...
Current thread 0x0000741e1ae78080 (most recent call first):
  File "h.py", line 6 in <module>
```

The process kept running. Line 4 is the `acquire`. The stack names the waiting line, and it does not name the holder: find who took the lock from the code or the other stacks. Without the registration, the default action of `SIGUSR1` ends the process, so never send it to a program that you have not checked.

## Node.js

Start with `--report-on-signal`, and `kill -USR2 PID` writes a JSON report with the JavaScript and native stacks, the heap figures and the open handles. Create the directory first: with `--report-directory=rep` and no `rep`, Node 24 printed `Failed to open Node.js report file` and the report was lost. The report also contains environment variables unless you exclude them; [what it exposes](/learn/node-diagnostic-report-secrets/) covers that.

A report triggered by a signal needs the event loop to turn. If JavaScript is stuck in a loop, expect nothing, and use a native profiler or attach an inspector that was enabled beforehand.

## If nothing was prepared

On Linux, these read state without stopping the process:

```
cat /proc/PID/wchan; echo
grep -E 'State|Threads|ctxt' /proc/PID/status
ls -l /proc/PID/fd | wc -l
ss -tnp | grep "pid=PID,"
```

Run the second one twice. Context-switch counts that do not move mean that no switch of the main thread was observed. It may have been blocked throughout, or running throughout, so compare CPU time as well: fields 14 and 15 of `/proc/PID/stat`, or `/proc/PID/task/TID/stat` for one thread, grow only while it runs. Reading another user's process needs matching privileges.

## Hand over

Both captures with their times, the CPU use between them, the process's start time and release, and which instance still hangs. If you must restart for users' sake, restart the others and take one instance out of rotation instead of killing it. Say when it will be killed, so that the receiver knows how long they have.

## Worked example

This example is fictional. Two dumps 30 seconds apart show twelve threads waiting in a pool and one in a socket read with no timeout, to the same host. Ana restarts nine workers and leaves one out of rotation. Ben confirms that its connection is still open on the other side, where the server has no such request. The fix is a read timeout, and the pool was never the cause.

Write the open explanations as in [an on-call handoff](/learn/on-call-investigation-handoff/). Return to [handing over evidence](/learn/engineering-handoff-evidence/).

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Remove the environment from a Node.js report before you share it](/learn/node-diagnostic-report-secrets/)
    
    Data leaks The Proofline team November 24, 2026 2 min read
    
-   ### [Hand over an incident you have not solved yet](/learn/on-call-investigation-handoff/)
    
    Deployment failures The Proofline team November 24, 2026 3 min read
