In this lesson, you will learn how to inspect the kernel call stack of a process to identify why it has stopped progressing and entered a permanently stalled state.
The "D" State Mystery
When a process enters the TASK_UNINTERRUPTIBLE state (often called "D" state or "Uninterruptible Sleep"), it means the kernel is waiting for an event—usually I/O completion—that hasn't arrived. Unlike a normal sleep state, this process cannot be killed or signaled because it is waiting for a critical kernel operation to finish. To find out what it is waiting for, we look at its kernel stack.
Inspecting the Stack
Every process has a kernel stack—a small memory area where the kernel stores the sequence of function calls it was executing when it switched to the blocked state. You can view this trace through the /proc filesystem.
If you have a PID (let's say 1234) that is stuck, run:
cat /proc/1234/stack
This command prints the list of functions currently on the process's stack. The function at the top is the one the process was executing when it went to sleep.
Reading the Trace
A typical stack trace for a process blocked on disk I/O might look like this:
[<0>] blk_mq_get_tag+0x140/0x2a0
[<0>] blk_mq_dispatch_rq_list+0x120/0x8d0
[<0>] blk_mq_do_dispatch_sched+0x2c0/0x3d0
[<0>] __blk_mq_sched_dispatch_requests+0x140/0x210
...
By reading this trace from top to bottom, you can see the "story" of the process. In this example, the process is calling blk_mq_get_tag. This tells you the process is stuck in the block layer, waiting for an available request tag from the hardware controller. If the trace shows a function related to nfs or network_fs, you know the bottleneck is your network storage mount rather than your local disk.
By comparing this stack to the kernel's source code, you can pinpoint exactly which synchronization primitive or hardware event is causing the hang.
Key Takeaway: The /proc/[pid]/stack file provides a snapshot of the kernel function call chain, allowing you to trace a stalled process back to the specific resource it is waiting for.