python-linux-procfs/python-linux-procfs-pflags-...

51 lines
1.5 KiB
Diff

From eb984b30e325bbf27844bf9c1f90767504468db5 Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Tue, 23 Nov 2021 13:01:05 -0500
Subject: [PATCH 2/3] python-linux-procfs: pflags: Handle pids that completed
Sometimes pids disappear when they are completed.
Programs such as pflags that use procfs must account for that.
The solution is to simply recognize this situation, and to continue.
Signed-off-by: John Kacur <jkacur@redhat.com>
---
pflags | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/pflags b/pflags
index 3407b6f51c96..46d396c87c2b 100755
--- a/pflags
+++ b/pflags
@@ -50,14 +50,25 @@ def main(argv):
pids = list(ps.processes.keys())
pids.sort()
- len_comms = [len(ps[pid]["stat"]["comm"]) for pid in pids if pid in ps]
+ len_comms = []
+ for pid in pids:
+ if pid in ps:
+ try:
+ len(ps[pid]["stat"]["comm"])
+ except (TypeError, FileNotFoundError):
+ continue
+ len_comms.append(len(ps[pid]["stat"]["comm"]))
+
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()
+ try:
+ flags = ps[pid].stat.process_flags()
+ except AttributeError:
+ continue
# Remove flags that were superseeded
if "PF_THREAD_BOUND" in flags and "PF_NO_SETAFFINITY" in flags:
flags.remove("PF_THREAD_BOUND")
--
2.31.1