Discussion:
[PATCH] python-linux-procfs: pflags: Ignore non-existent pids or process names
John Kacur
2018-11-29 14:43:50 UTC
Permalink
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 <***@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
_______________________________________________
tuna-devel mailing list -- tuna-***@lists.fedorahosted.org
To unsubscribe send an email to tuna-devel-***@lists.fedorahosted.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedorahosted.org/archives/list/tuna-
Loading...