Create a gist now

Instantly share code, notes, and snippets.

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