summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2008-12-08 13:43:14 -0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2008-12-08 13:43:14 -0200
commitba15d16378c5d83638cb16ce2eee9948f6d99059 (patch)
treeffa477f10cb9f17df17ebb24610e8a20f277d593
parente3c84670cea0d9d8179f20ef9789c87428547a32 (diff)
downloadpython-linux-procfs-ba15d16378c5d83638cb16ce2eee9948f6d99059.tar.gz
pidstats: Remove dead processes in find_by_name()
Since we now defer looking at the contents till we really need to parse the files, we have to check if the process died in this method. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rwxr-xr-xprocfs/procfs.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/procfs/procfs.py b/procfs/procfs.py
index 9c0ccac..c972438 100755
--- a/procfs/procfs.py
+++ b/procfs/procfs.py
@@ -215,8 +215,15 @@ class pidstats:
name = name[:15]
pids = []
for pid in self.processes.keys():
- if self.processes[pid]["stat"]["comm"] == name:
- pids.append(pid)
+ try:
+ if name == self.processes[pid]["stat"]["comm"]:
+ pids.append(pid)
+ except IOError:
+ # We're doing late loading of /proc files
+ # So if we get this exception is because the
+ # process vanished, remove it
+ del self.processes[pid]
+
return pids
def find_by_regex(self, regex):