Skip to content

Instantly share code, notes, and snippets.

@amr
Created November 30, 2010 18:37
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save amr/722145 to your computer and use it in GitHub Desktop.
Save amr/722145 to your computer and use it in GitHub Desktop.
Find processes executing futex with FUTEX_WAIT (helps find deadlock-ed processes)
#!/bin/bash
#
# Find all processes that are executing a futex(2) call with op=FUTEX_WAIT
# In some cases this can be helpful in finding deadlock-ed processes.
#
test ! $UID -eq 0 && echo -e "WARNING: Not running as root, only processes for this user are being scanned\n" >&2;
pids=$(ps -u $UID -opid --no-headers)
for pid in $pids; do
cat /proc/$pid/syscall |
awk "{if (\$1 == 202 && \$3 == \"0x0\") {
print $pid
}}";
# $1 is the syscall, we compare to 202 which is the futex call
# See: /usr/include/asm/unistd.h
# $2 is the 1st param, $3 is the 2nd param, etc
# We compare the second param to 0x0 which is FUTEX_WAIT
# See: /usr/include/linux/futex.h
done
@liuyangc3
Copy link

nice work but I get an error when use this script:

[root@xxx ~]# /data0/script/find-futex-wait.sh
2046
2083
2162
cat: /proc/2529/syscall: No such file or directory

and I fix it in my fork

https://gist.github.com/liuyangc3/bc7a47d3c2eaa06b499d

@gleventhal
Copy link

You can also probably do:
ps -eo pid,wchan:32 | grep futex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment