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 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 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. Return to handing over evidence.