Skip to content

Instantly share code, notes, and snippets.

@yaniv-aknin
Created October 26, 2012 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaniv-aknin/3957499 to your computer and use it in GitHub Desktop.
Save yaniv-aknin/3957499 to your computer and use it in GitHub Desktop.
Check what a process is blocking on using the CLI on Linux

Suppose I have blocking process blocking_process:

import os

os.system('rm -fr /tmp/pipe; mkfifo /tmp/pipe')
print len(open('/tmp/pipe').read())

On Linux, I might check what is it blocking on by doing:

$ strace -p $(pgrep -f blocking_process)
Process 5151 attached - interrupt to quit
open("/tmp/pipe", O_RDONLY ^C
$

If it were blocking on an incomplete system call with a file descriptor in it (i.e., read(3) I would do something like ls -l /proc/$(pgrep -f blocking_process)/fd/3 to know more about the file it's blocking on.

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