MCPcopy Create free account
hub / github.com/apache/cloudstack / CsProcess

Class CsProcess

systemvm/debian/opt/cloud/bin/cs/CsProcess.py:24–65  ·  view source on GitHub ↗

Manipulate processes

Source from the content-addressed store, hash-verified

22
23
24class CsProcess(object):
25 """ Manipulate processes """
26
27 def __init__(self, search):
28 self.search = search
29
30 def start(self, thru, background=''):
31 # if(background):
32 # cmd = cmd + " &"
33 logging.info("Started %s", " ".join(self.search))
34 os.system("%s %s %s" % (thru, " ".join(self.search), background))
35
36 def kill_all(self):
37 pids = self.find_pid()
38 for p in pids:
39 CsHelper.execute("kill -9 %s" % p)
40
41 def find_pid(self):
42 self.pid = []
43 items = len(self.search)
44 for i in CsHelper.execute("ps aux"):
45 proc = re.split(r"\s+", i)[10:]
46 matches = len([m for m in proc if m in self.search])
47 if matches == items:
48 self.pid.append(re.split(r"\s+", i)[1])
49
50 logging.debug("CsProcess:: Searching for process ==> %s and found PIDs ==> %s", self.search, self.pid)
51 return self.pid
52
53 def find(self):
54 has_pid = len(self.find_pid()) > 0
55 return has_pid
56
57 def kill(self, pid):
58 if pid > 1:
59 CsHelper.execute("kill -9 %s" % pid)
60
61 def grep(self, str):
62 for i in CsHelper.execute("ps aux"):
63 if i.find(str) != -1:
64 return re.split(r"\s+", i)[1]
65 return -1

Callers 4

__updateMethod · 0.90
_redundant_onMethod · 0.90
processMethod · 0.90
test_initMethod · 0.90

Calls

no outgoing calls

Tested by 1

test_initMethod · 0.72