[Yum-devel] [PATCH 2/3] add two functions to get list of processes and return the files the processes have open
Seth Vidal
skvidal at fedoraproject.org
Tue Dec 8 21:45:01 UTC 2009
---
yum/misc.py | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/yum/misc.py b/yum/misc.py
index 642f9a2..bfebc38 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -873,3 +873,33 @@ def get_my_lang_code():
return mylang
+def return_running_pids():
+ """return list of running processids, excluding this one"""
+ mypid = os.getpid()
+ pids = []
+ for fn in glob.glob('/proc/[0123456789]*'):
+ if mypid == os.path.basename(fn):
+ continue
+ pids.append(os.path.basename(fn))
+ return pids
+
+def get_open_files(pid):
+ """returns files open from this pid"""
+ files = []
+ smaps = '/proc/%s/smaps' % pid
+ try:
+ maps = open(smaps, 'r')
+ except (IOError, OSError), e:
+ return files
+
+ for line in maps.readlines():
+ if line.find('fd:') == -1:
+ continue
+ line = line.replace('\n', '')
+ slash = line.find('/')
+ filename = line[slash:]
+ filename = filename.replace('(deleted)', '') #only mildly retarded
+ filename = filename.strip()
+ if filename not in files:
+ files.append(filename)
+ return files
--
1.6.5.2
More information about the Yum-devel
mailing list