My hung process had no file open. It was stuck inside open().

My hung process had no file open. It was stuck inside open().

●2 ●43 ●105
calendar_today ago • schedule1 min read

I built the smallest hang I know on my own machine: a named pipe in a scratch directory, and cat reading it in the background with nobody ever writing to it. No output, no error, no exit. The reflex is kill -9 and a rerun. I read /proc first, because a killed process takes its reasons with it:

$ mkfifo job.fifo; cat job.fifo > out.log 2>&1 & P=$!
$ cat /proc/$P/wchan; echo
wait_for_partner
$ ps -o stat,wchan:32,cmd -p $P
STAT WCHAN                            CMD
S    wait_for_partner                 cat job.fifo
$ cut -d' ' -f1 /proc/$P/syscall
257

S means interruptible sleep, so signals still work. wait_for_partner is the kernel waiting for a FIFO writer, and syscall 257 is openat on x86_64. The fd table held only 0, 1 and 2: cat had not opened the pipe yet, it was still inside the open. When I opened the other end from a subshell, the wait moved to anon_pipe_read and syscall 0, read. Two different bugs, one symptom.

Then I repeated the hang and sent kill -9. Exit 137, /proc/$P gone, every one of those answers with it. None of the reads above needed root.

The process-state table, the D-state case where kill -9 does nothing, and a capture script to run before any kill are in the full hung-process diagnosis guide.


I bundled the scripts I copy onto every new server, plus 10 bonus ones, into the Production Bash Toolkit. 30-day refund if it isn't useful.

Want more #devops & #devops deep dives?

Join 6,182+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

2 Comments

1 vote
1

More Posts

The cleanup failed on the night there was nothing to clean

BashSnippets - Dec 2

A deploy guard that passes with no token

BashSnippets - Nov 24

My 30-day log cleanup kept a file that was 30 and a half days old

BashSnippets - Oct 8

Every disk-alert script I had piped into a command this machine does not have

BashSnippets - Oct 15

I killed the process I started. The port stayed taken.

BashSnippets - Nov 5
chevron_left
4k Points • 150 Badges
North America • bashsnippets.xyz
79Posts
44Comments
14Connections
Linux user who got tired of Googling the same bash commands every time I sat down at a terminal. Sta... Show more

Related Jobs

View all jobs →

Commenters (This Week)

7 comments
3 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!