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
This commit is contained in:
parent
23d326155b
commit
e9387fc973
1 changed files with 28 additions and 0 deletions
|
@ -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"
|
||||
|
@ -311,6 +324,21 @@ class test:
|
|||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue