From e9387fc973a6dca6bddb22c1331ef0285d3babea Mon Sep 17 00:00:00 2001 From: kriss Date: Sat, 15 Mar 2008 22:44:52 +0000 Subject: [PATCH] FEATURE: Added function process_running() to look up if a process is running (by name). TEST: Added test function for process_running(). git-svn-id: http://www.neo1973-germany.de/svn@57 46df4e5c-bc4e-4628-a0fc-830ba316316d --- .../trunk/src/settingsgui/ProcessInterface.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/SettingsGUI/trunk/src/settingsgui/ProcessInterface.py b/SettingsGUI/trunk/src/settingsgui/ProcessInterface.py index e74c03d..11a01fd 100644 --- a/SettingsGUI/trunk/src/settingsgui/ProcessInterface.py +++ b/SettingsGUI/trunk/src/settingsgui/ProcessInterface.py @@ -280,6 +280,19 @@ class ProcessInterface: + +def process_running(name): + if not os.path.exists("/proc"): + return False + for key in os.listdir("/proc"): + if key.replace("/proc/", ""): + if key.isdigit(): + fd = open(os.path.join("/proc/", key, "cmdline")) + if fd.read().find(name) >= 0: + return True + return False + + class test: def do_test(self): print "Test interface" @@ -310,6 +323,21 @@ class test: time.sleep(0.1) ## wait for command to compute print "output of ls was [%s]" % ls.read_from_process() + + def process_running_test(self): + print "Testing if process by name \"python\" is running... ", + if process_running("python"): + print "yes [OKAY]" + else: + print "no [ERROR?!]" + + print "Testing if process by name \"ononenamesitso\" is running... ", + if process_running("ononenamesitso"): + print "yes [ERROR?!]" + else: + print "no [OKAY]" + + # ToDo remove ## self.process = subprocess.Popen(self.command, cwd = self.cwd, shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE, stdin = subprocess.PIPE)