python-linux-procfs/SOURCES/pflags_Ignore_non-existent_...

40 lines
1.2 KiB
Diff

From 5b180973d90475ab32c470e568f1c786d94a9bf0 Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Thu, 29 Nov 2018 15:39:22 +0100
Subject: [PATCH] python-linux-procfs: pflags: Ignore non-existent pids or
process names
If the user enters a non-existent pid or process name, skip over it,
Also, if the user enters nothing but a non-existent pid, then make sure
the max_comm_len defaults to 0 instead of generating an error.
Signed-off-by: John Kacur <jkacur@redhat.com>
---
pflags | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/pflags b/pflags
index a1667fc06131..9c45600cc1ee 100755
--- a/pflags
+++ b/pflags
@@ -50,11 +50,13 @@ def main(argv):
pids = list(ps.processes.keys())
pids.sort()
- len_comms = [len(ps[pid]["stat"]["comm"]) for pid in pids]
- max_comm_len = max(len_comms)
+ len_comms = [len(ps[pid]["stat"]["comm"]) for pid in pids if pid in ps]
+ max_comm_len = max(len_comms, default=0)
del(len_comms)
for pid in pids:
+ if pid not in ps:
+ continue
flags = ps[pid].stat.process_flags()
# Remove flags that were superseeded
if "PF_THREAD_BOUND" in flags and "PF_NO_SETAFFINITY" in flags:
--
2.19.2