Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import sys
import time
def is_sleeping(pid):
with open("/proc/%d/stat" % pid) as stat:
state =
return state[2] == 'S'
def io_stats(pid):
with open("/proc/%d/io" % pid) as io:
stats = (stat.split(": ") for stat in io.readlines())
return {stat[0]: int(stat[1]) for stat in stats}
if __name__ == '__main__':
pid = int(sys.argv[1])
while True:
stats = io_stats(pid)
last_diff = stats['read_bytes'] - stats['rchar']
while is_sleeping(pid):
stats = io_stats(pid)
cur_diff = stats['read_bytes'] - stats['rchar']
if cur_diff == last_diff:
print("Process seems to be blocked reading the terminal!")
print("Process is blocked doing something else")
last_diff = cur_diff
print('Process is not sleeping anymore')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment