diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2008-02-26 12:54:14 -0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2008-02-26 12:54:14 -0300 |
commit | 9c97bbb0f69f8b57c34abd6e1daf01ce70165e7d (patch) | |
tree | 3be1161c0fd08beb0579244537d27c12b99ba6d3 | |
parent | bcb8b4401c721056ff5bb902f228b9b451a6985f (diff) | |
download | python-linux-procfs-9c97bbb0f69f8b57c34abd6e1daf01ce70165e7d.tar.gz |
[PIDSTATS]: Check if process has vanished when accessing cmdline & tasks/
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rwxr-xr-x | procfs/procfs.py | 32 | ||||
-rw-r--r-- | rpm/SPECS/python-linux-procfs.spec | 2 |
2 files changed, 21 insertions, 13 deletions
diff --git a/procfs/procfs.py b/procfs/procfs.py index 102503b..e5a8acf 100755 --- a/procfs/procfs.py +++ b/procfs/procfs.py @@ -4,7 +4,7 @@ import os, time, utilist -VERSION="0.1" +VERSION="0.2" def process_cmdline(pid_info): if pid_info.has_key("cmdline"): @@ -90,22 +90,30 @@ class pidstats: def reload_threads(self): for pid in self.processes.keys(): - threads = pidstats("/proc/%d/task/" % pid) - # remove thread leader - del threads[pid] - if not threads.keys(): - continue - self.processes[pid]["threads"] = threads + try: + threads = pidstats("/proc/%d/task/" % pid) + # remove thread leader + del threads[pid] + if not threads.keys(): + continue + self.processes[pid]["threads"] = threads + except OSError: + # process vanished, remove it + del self.processes[pid] def load_cmdline(self): for pid in self.processes.keys(): if self.processes[pid].has_key("cmdline"): continue - f = file("/proc/%d/cmdline" % pid) - line = f.readline() - if line: - self.processes[pid]["cmdline"] = line.strip().split('\0') - f.close() + try: + f = file("/proc/%d/cmdline" % pid) + line = f.readline() + if line: + self.processes[pid]["cmdline"] = line.strip().split('\0') + f.close() + except OSError: + # process vanished, remove it + del self.processes[pid] def find_by_name(self, name): name = name[:15] diff --git a/rpm/SPECS/python-linux-procfs.spec b/rpm/SPECS/python-linux-procfs.spec index 6379619..b7e054a 100644 --- a/rpm/SPECS/python-linux-procfs.spec +++ b/rpm/SPECS/python-linux-procfs.spec @@ -1,7 +1,7 @@ %{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} Name: python-linux-procfs -Version: 0.1 +Version: 0.2 Release: 1%{?dist} License: GPLv2 Summary: Linux /proc abstraction classes |