Stop hitting Ctrl+C blindly and read what the kernel already knows about your frozen process

You run df -h on a production box, or kick off a deployment script, or type ls /mnt/backups. Nothing comes back. The cursor sits on a blank line and blinks.

Ten seconds pass. Then a minute. You slam Ctrl+C, and the terminal still refuses to give your prompt back.

At that point, most people open a second SSH session and fire kill -9 at the PID. Sometimes that works. Other times even kill -9 does nothing at all, and worse, you just destroyed the only runtime evidence explaining why the server stalled in the first place.

A hanging Linux command is rarely "doing nothing." It is blocked inside a specific system call, waiting on a network socket, locked behind another PID, prompting for unseen input, or asleep inside the kernel waiting on storage that stopped answering. Read what the kernel already tracks before guessing.

First, check the process state and wait channel

Before attaching strace or pulling out heavy profilers, ask ps two questions: what state is the process in, and what kernel function put it to sleep?

ps -eo pid,ppid,stat,wchan:32,comm | grep -E "STAT|df|rsync|curl|apt" 

The STAT column tells you how the kernel scheduler currently treats that thread. Four state letters show up constantly when commands hang:

  • S means interruptible sleep. The process called a blocking syscall like read(), poll(), select(), or connect(), and the kernel parked it until data arrives or a signal wakes it up. Ctrl+C (SIGINT) and SIGTERM work here.
  • D means uninterruptible sleep. The thread is stuck inside a kernel-mode operation, usually disk I/O, an NFS mount, or a hardware driver lock. Signals are queued until that kernel call returns. Even kill -9 will not kill a D-state process while it remains stuck in the kernel.
  • R means running or runnable. The command is not waiting on an external resource at all; it is burning CPU in a tight user-space loop or waiting in the scheduler run queue because the machine is CPU-starved.
  • T means stopped. Someone hit Ctrl+Z, sent SIGSTOP, or left a debugger attached to the process.

Right next to STAT sits wchan, short for wait channel. The :32 modifier matters because older ps output truncates symbol names down to six characters, leaving you staring at useless fragments. With wchan:32, you get the full kernel function name where the process went to sleep:

 PID PPID STAT WCHAN COMMAND 18412 18390 D+ rpc_wait_bit_killable df 19044 18911 S+ ep_poll curl 19520 19402 S+ pipe_wait tar 20118 19980 S futex_wait_queue python3 

Look how much signal comes out of one ps line. PID 18412 (df) sits in rpc_wait_bit_killable, pointing to a stalled NFS or SunRPC mount. PID 19044 is in ep_poll, meaning curl waits on a socket or DNS reply. PID 19520 is blocked on pipe_wait because the other end of its pipe stopped reading or writing. PID 20118 sits in futex_wait_queue, pointing to mutex or lock contention inside Python.

You can also read the wait channel straight from /proc for a known PID:

cat /proc/18412/wchan 

If /proc/<PID>/wchan prints 0, the process is currently executing rather than sleeping. Any other symbol name gives you the exact kernel gatekeeper holding your process hostage.

Inspect /proc before attaching invasive debuggers

Many engineers jump straight to strace -p <PID> when something stalls. On a busy production service, that reflex carries two traps. strace uses ptrace, which pauses the target at every syscall boundary and slows multi-threaded runtimes down sharply. Even worse, if the process sits in D state inside the kernel, strace freezes your own shell too because ptrace waits for the kernel syscall to exit before returning control.

Reading /proc skips both traps. Those virtual files are read-only snapshots from kernel task structs and never pause the target thread.

Start with /proc/<PID>/syscall:

sudo cat /proc/19044/syscall 

Sample output:

232 0x4 0x7fff4c2a1b80 0x40 0x1388 0x7f9c12004800 0x10 0x7fff4c2a1b48 0x7f9c124f9c2a 

The first number is the system call ID, followed by six hex register arguments, the stack pointer, and the instruction pointer. On x86_64 Linux, syscall 232 is epoll_wait. Syscall 0 is read, 1 is write, 7 is poll, 42 is connect, 61 is wait4, and 202 is futex. If the process runs user-space code at that instant, /proc/<PID>/syscall prints running.

Note that the second token (0x4 in the example above) is the first argument passed to the syscall. For read, write, or epoll_wait, that first argument is the file descriptor number: fd 4 in decimal. Now you already know which descriptor to inspect next without running a single trace tool.

Next, check the full kernel call trace of that sleeping thread:

sudo cat /proc/19044/stack 

For an NFS hang (D state), /proc/<PID>/stack gives you an unmistakable trace:

[<0>] rpc_wait_bit_killable+0x28/0xa0 [sunrpc] [<0>] __rpc_execute+0x154/0x410 [sunrpc] [<0>] rpc_run_task+0x149/0x1a0 [sunrpc] [<0>] nfs4_call_sync_sequence+0x6e/0xb0 [nfsv4] [<0>] nfs4_proc_statfs+0x6b/0xa0 [nfsv4] [<0>] statfs_by_dentry+0x67/0x90 [<0>] vfs_statfs+0x16/0xd0 

There is zero guesswork here. df called vfs_statfs(), walked into nfs4_proc_statfs(), dispatched an RPC over sunrpc, and went to sleep waiting on a storage server that stopped answering.

One more /proc file tells you whether the command is dead frozen or retrying in a loop:

grep ctxt /proc/19044/status 

Run that twice, five seconds apart:

voluntary_ctxt_switches: 412 nonvoluntary_ctxt_switches: 19 

If voluntary_ctxt_switches stays at 412 on both checks, the thread stayed parked on the exact same blocking call. If it climbs by hundreds per second while your terminal looks dead, the command is waking up repeatedly on timeouts or EAGAIN retries.

Use strace to catch the blocking syscall live

When the process is in S state and /proc points to a user-space loop or an unclear wait, attach strace:

sudo strace -tt -T -f -p 19520 

Here is what those flags buy you:

  • -tt: microsecond timestamps to separate a 2-second retry from a permanent block.
  • -T: duration spent inside every completed syscall.
  • -f: follows child processes and threads, catching cases where the main PID sits in wait4() while a subprocess hangs.

When you attach strace to a stalled process, notice how the last line has no closing parenthesis or return value yet:

14:22:08.114203 read(0, 

That incomplete line is gold. strace prints the syscall name and arguments on entry, then pauses output until the syscall returns. Seeing read(0, means the process is blocked reading file descriptor 0 (standard input). Somebody's automated deployment script ran unzip, rm -i, apt, or ssh without batch flags, and it is silently sitting there waiting for a human to type y or a password on a non-interactive shell.

Other common incomplete lines tell different stories immediately:

connect(5, {sa_family=AF_INET, sin_addr=inet_addr("10.42.8.19"), sin_port=htons(5432)}, 16 means a TCP handshake is hanging. A firewall or cloud security group is dropping SYN packets silently instead of rejecting them, forcing Linux to burn through net.ipv4.tcp_syn_retries (around 127 seconds by default with tcp_syn_retries=6) before timing out.

flock(3, LOCK_EX means another script or cron job holds an exclusive file lock on fd 3.

wait4(20411, means PID 19520 is just a wrapper shell or Python parent waiting for child PID 20411 to exit. Now you know to inspect 20411 instead.

If you run Debian or Ubuntu and strace -p <PID> fails with Operation not permitted even when you own the process, that is Yama ptrace hardening (kernel.yama.ptrace_scope = 1), which blocks non-parent processes from attaching without sudo. Just prepend sudo rather than disabling the sysctl on production hosts.

Map mystery file descriptors back to files, pipes, and sockets

Knowing a process is blocked on read(7, ...) or flock(3, LOCK_EX) leaves one obvious question: what on earth is file descriptor 7?

Inspect /proc/<PID>/fd first, because ls -l resolves kernel symlinks cleanly without blocking:

ls -la /proc/19520/fd 

You will see something like:

lrwx------ 1 root root 64 Dec 5 14:19 0 -> /dev/pts/2 lrwx------ 1 root root 64 Dec 5 14:19 1 -> /dev/pts/2 lrwx------ 1 root root 64 Dec 5 14:19 2 -> /dev/pts/2 lr-x------ 1 root root 64 Dec 5 14:19 3 -> /var/lock/db-backup.lock l-wx------ 1 root root 64 Dec 5 14:19 4 -> pipe:[948210] lrwx------ 1 root root 64 Dec 5 14:19 5 -> socket:[949112] 

And if you want the current offset, open flags, or lock metadata for fd 3, read /proc/<PID>/fdinfo/3:

cat /proc/19520/fdinfo/3 

When fd 3 points to a locked file, lslocks exposes the exact PID holding that lock:

sudo lslocks | grep db-backup.lock 

Output:

cron-backup 17201 FLOCK 20B WRITE 0 0 0 /var/lock/db-backup.lock pg_dump_wrap 19520 FLOCK 20B WRITE 0 0 0 /var/lock/db-backup.lock (blocked) 

Notice (blocked) on PID 19520 and the holder PID 17201 right above it. That turns a mysterious hang into a five-second root cause.

Now what about pipe:[948210]? Pipe hangs trip people up constantly in CI/CD runners, Jenkins agents, and systemd hooks. Suppose a script runs a background daemon and pipes stdout back to SSH or Ansible. Even after the main script finishes, SSH hangs forever because the background child inherited the write end of pipe:[948210] and kept it open.

Find both ends of that pipe inode across the whole system:

sudo lsof -b -n -P | grep 948210 

Watch those three lsof flags closely: -n skips DNS lookups, -P skips /etc/services port translations, and -b tells lsof to avoid kernel functions that might block, like stat() or readlink() on a dead filesystem mount. Forgetting -b -n -P is the fastest way to hang your own diagnostic shell while trying to diagnose a hung command.

If lsof is not installed on a stripped container or minimal server, /proc gives you the exact same pipe lookup in pure bash:

ls -l /proc/[0-9]*/fd/* 2>/dev/null | grep "948210" 

Every matching PID shows up with its file descriptor symlink pointing to pipe:[948210].

Network stalls, silent firewalls, and broken DNS

When wchan reads sk_wait_data, inet_csk_accept, or ep_poll, or fd points to socket:[949112], ss shows you the network side immediately.

sudo ss -tanp | grep 19044 

You are looking for two specific states:

If the socket sits in SYN-SENT, your server sent the TCP SYN packet and never got a SYN-ACK or an ICMP reset back:

SYN-SENT 0 1 10.0.1.14:48322 10.42.8.19:5432 users:(("curl",pid=19044,fd=5)) 

A rejected port returns ECONNREFUSED in less than a millisecond. A silently dropped packet leaves your command hanging in SYN-SENT for two minutes while the kernel retries with exponential backoff. Check firewall rules (iptables, nftables, AWS security groups, Azure NSGs) or routing on the path to 10.42.8.19:5432.

If the socket is already ESTAB, look at Recv-Q and Send-Q in ss -tanp. A non-zero Send-Q that never drains means the remote peer's TCP receive window collapsed or packets are dropping on the wire (check ss -ti for retrans and rto). A Recv-Q sitting at 0 on ESTAB means the handshake finished, your command sent its payload, and the remote API or database stopped sending bytes back.

Then there is the classic hidden culprit: UDP DNS stalls. Run sudo ss -uap | grep 19044 and check if your command has an open UDP socket to port 53. Standard glibc getaddrinfo() reads /etc/resolv.conf top to bottom. If the first nameserver entry is unreachable (an old VPN DNS IP or a dead VPC resolver), glibc waits for its timeout (5 seconds per attempt by default) before trying the second server, and it repeats that stall for every lookup unless options timeout:1 attempts:2 or rotate is tuned, or a local caching resolver is running.

When D state hits: NFS, dead disks, and storage locks

Uninterruptible sleep (D state) deserves separate handling because standard debugging intuitions break down completely here.

I once watched an engineer run df -h to check disk usage, see it hang, open a new SSH tab, run df -h again to "double-check," and end up with four wedged SSH sessions stacked on a single dead NFS mount. df -h iterates over every mount in /proc/mounts and calls statfs() on each one. If /mnt/archive is a hard-mounted NFS share whose storage server dropped offline, every df invocation freezes at /mnt/archive.

Check kernel logs right away:

dmesg -T | tail -n 30 

Or on systemd hosts:

journalctl -k -n 40 --no-pager 

Look for messages like:

[Dec 5 14:15:02] nfs: server 10.10.20.50 not responding, still trying [Dec 5 14:16:18] INFO: task df:18412 blocked for more than 120 seconds. 

That second line comes from the kernel hung-task detector (kernel.hung_task_timeout_secs, typically 120 seconds), and it often prints a full kernel stack trace straight into dmesg for you.

If the mount is not NFS, inspect the local disk I/O queues with iostat:

iostat -xz 1 5 

Watch await (average I/O wait in milliseconds) and aqu-sz (average queue depth). When a dying NVMe drive or overloaded SAN volume starts dropping commands, aqu-sz spikes while completion throughput drops near zero, pushing every process touching that block device into D state.

To check local disk space without triggering a dead network mount hang, pass -l (local filesystems only) or wrap risky commands in timeout:

df -hl timeout 3 df -h 

And if a dead NFS mount is freezing monitoring agents across the node, umount -l /mnt/archive (lazy unmount) detaches the mount namespace immediately so new commands stop hitting it, even if old stuck processes wait until the network recovers or the server reboots cleanly.

Hidden interactive prompts and orphan child trees

Not every hang involves the kernel network stack or failing disks. Plenty of "frozen" commands are sitting there waiting for a human who is not at the keyboard.

Check the process tree under your command:

pstree -ap 19520 

You might run a backup script, check ps, and assume backup.sh hung, only to see pstree reveal:

bash,19520 /usr/local/bin/backup.sh `-gpg,19588 --symmetric /tmp/dump.tar 

If ssh waits on host confirmation (Are you sure you want to continue connecting (yes/no)?), sudo asks for a password without NOPASSWD, unzip asks to overwrite a file, or systemctl status opens less inside a script, the same stall hits. Check fd 0 and 1 on the leaf child:

ls -la /proc/19588/fd/0 /proc/19588/fd/1 

If fd 0 points to a pipe with no writer or a pseudo-terminal nobody is typing into, add explicit non-interactive flags in your automation: ssh -o BatchMode=yes, DEBIAN_FRONTEND=noninteractive, GIT_TERMINAL_PROMPT=0, and SYSTEMD_PAGER="".

An interesting fact about Linux load average and D state

Most sysadmins treat the Linux load average (uptime, top) as a pure CPU utilization gauge. On macOS, Solaris, and BSD systems, that mental model holds true because load average tracks runnable and running CPU threads.

Linux breaks that assumption on purpose. Inside kernel/sched/loadavg.c, the Linux kernel counts tasks in uninterruptible sleep (TASK_UNINTERRUPTIBLE, D state) right alongside runnable tasks (TASK_RUNNING) when computing the 1-, 5-, and 15-minute load averages. That behavior dates back to a 1993 kernel patch by Matthias Urlichs so system load would reflect overall machine demand, including processes stalled on disk or network storage I/O.

That is why a single hung NFS server can drive a Linux host's load average above 80.00 while top shows CPU usage sitting at 99% idle. High load average with zero CPU burn is one of the fastest fingerprints of widespread D-state blocking.

My 15-second hang triage checklist

Before reaching for kill on a stalled command, run these four checks in a second shell:

  1. Run ps -eo pid,ppid,stat,wchan:32,comm | grep <cmd> to separate D (kernel I/O), S (sleep), T (stopped), and R (CPU spin).
  2. Read /proc/<PID>/stack and /proc/<PID>/syscall as root to see the kernel call path and blocking descriptor without pausing threads.
  3. Inspect /proc/<PID>/fd and sudo lsof -b -n -P -p <PID> (plus sudo lslocks for lockfiles) to resolve the fd to a file, pipe, lock, or socket.
  4. Check sudo ss -tanp | grep <PID> and sudo ss -uap | grep <PID> for network stalls or dead DNS resolvers; for D state, check dmesg -T | tail -n 30 and iostat -xz 1.

Drop this helper into ~/.bashrc so you never mistype the /proc paths during an outage:

waitwhat() { local pid="$1" [ -z "$pid" ] && echo "Usage: waitwhat <pid>" && return 1 ps -p "$pid" -o pid,ppid,stat,wchan:32,comm echo "--- /proc/$pid/syscall ---" sudo cat "/proc/$pid/syscall" 2>/dev/null echo "--- /proc/$pid/stack ---" sudo cat "/proc/$pid/stack" 2>/dev/null echo "--- open fds ---" sudo ls -la "/proc/$pid/fd" 2>/dev/null } 

Once rpc_wait_bit_killable, flock, read(0,, or SYN-SENT shows up in plain text, you fix the real blocker instead of restarting blind.

What is the trickiest hanging process you had to track down in production, and which command finally exposed what it was waiting on?

If this breakdown saved you hours of debugging or gave you something practical to use in production, consider buying me a coffee. Your support directly fuels independent, zero-fluff Linux and DevOps technical guides.

About the Author

Asep Sayyad is a Linux and DevOps engineer passionate about Linux administration, automation, cloud technologies, containers, and open-source software. He enjoys solving real-world infrastructure challenges and sharing practical knowledge through in-depth technical articles, tutorials, and hands-on guides.

His goal is to help aspiring and experienced engineers build stronger Linux and DevOps skills with content focused on real production scenarios rather than theory alone.

Connect with Me

Enjoyed this article?

If this guide saved you hours of debugging or gave you something practical for production, consider:

  • Buying me a coffee: Your support directly fuels independent, zero-fluff Linux and DevOps engineering breakdowns.
  • Starring my open-source projects on GitHub.
  • Sharing this article with fellow Linux and DevOps engineers.

You can also follow me for more practical content on Linux, DevOps, Cloud, Containers, Automation, and Open Source. Thanks for reading, and enjoy your learning!

© 2026 Asep Sayyad