brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ps shows the Linux processes stuck in D state, the ones that drive up load without CPU

Linux
~/tips/tip-linux-ps-d-state-processes

ps -eo stat,pid,wchan:32,cmd | awk '$1 ~ /^D/'

Find what makes the load average high while the CPU looks idle.

A load average of 20 on a machine where top shows the CPU mostly idle is confusing. On Linux, the load also counts processes that wait for disk or network storage, in what is called uninterruptible sleep, or D state.

ps -eo stat,pid,wchan:32,cmd | awk '$1 ~ /^D/'

The stat column starts with D for these processes. The wchan column shows the kernel function each one is waiting in, which often hints at the cause: names with nfs point to a network share, names with blk, io or a filesystem name point to a slow or failing disk.

One process in D for a moment is normal; every disk read passes through it. A long list that stays there is not. Run the command a few times in a row to see whether the same PIDs keep showing up.

To catch it over time:

watch -n 1 "ps -eo stat,pid,wchan:32,cmd | awk '\$1 ~ /^D/'"

The usual suspects are a NAS share that stopped answering, a USB disk with errors, or a disk that is simply overloaded. The kernel log often has matching messages about hung tasks or I/O errors.

You cannot kill a process in D state, not even with kill -9. The signal waits until the process comes back from the kernel, which may be never if the storage is gone. The fix is on the storage side: bring the share back, or unmount it, or replace the disk.

Further reading: ps(1) manual page, proc_pid_stat(5) manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link