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(a)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