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")