Linux Process Stack Trace: Find Where a Hung Process Is Stuck

Quick Linux Tip #127:

Question: A process is hung. Where is it stuck in the code?

Try: sudo cat /proc/3456/stack

Info: Displays kernel stack traces and wait channels to pinpoint where processes are blocked.

Examples:

  • $ sudo cat /proc/*/wchan 2>/dev/null | sort | uniq -c | sort -rn  # Analyze wait channels system-wide
  • $ sudo ps axo pid,stat,wchan,comm | awk '$2 ~ /D/'  # List all processes stuck in uninterruptible sleep
  • $ sudo pystack dump 3456  # Generate a detailed Python-specific call stack dump

Note: Processes in the D state (uninterruptible sleep) typically indicate I/O waits, whereas futex_wait signifies a mutex lock. Sample processes multiple times to verify if execution is progressing.




LinuxTeck.com
linuxteck:~$ sudo cat /proc/3456/stack
[<0>] futex_wait_queue_me+0xc4/0x120
[<0>] futex_wait+0x10e/0x260
[<0>] do_futex+0x133/0xaa0
[<0>] __x64_sys_futex+0x13e/0x180
[<0>] do_syscall_64+0x5c/0x90
[<0>] entry_SYSCALL_64_after_hwframe+0x72/0xdc

linuxteck:~$ sudo cat /proc/3456/wchan; echo
futex_wait_queue_me

linuxteck:~$ sudo cat /proc/3456/status | grep State
State: S (sleeping)
linuxteck:~$

PREVIOUS ARTICLE Quick Linux Tip #126: Linux Immutable File Attribute: Fix Files That Won't Delete NEXT ARTICLE Quick Linux Tip #128: ShellCheck Bash Script: Find Bugs and Security Issues in Linux
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.