From e3c0bb3ca105d0fc91fc347e50842c553f633fa5 Mon Sep 17 00:00:00 2001 From: Alexey Avramov Date: Wed, 11 Sep 2019 00:26:21 +0900 Subject: [PATCH] Fix pid_to_state() --- nohang | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nohang b/nohang index 6a1972d..e4f5335 100755 --- a/nohang +++ b/nohang @@ -420,11 +420,14 @@ def pid_to_state(pid): """ try: with open('/proc/' + pid + '/stat', 'rb') as f: - return f.read(20).decode('utf-8', 'ignore').rpartition(')')[2][1] + return f.read(40).decode('utf-8', 'ignore').rpartition(')')[2][1] except FileNotFoundError: return '' except ProcessLookupError: return '' + except IndexError: + with open('/proc/' + pid + '/stat', 'rb') as f: + return f.read().decode('utf-8', 'ignore').rpartition(')')[2][1] def pid_to_name(pid):