fix mac bug

Signed-off-by: deveco_test <liguangjie1@huawei.com>
This commit is contained in:
deveco_test
2022-07-26 14:27:33 +08:00
parent dd82791923
commit d5cdeeffbd
2 changed files with 23 additions and 6 deletions
+18 -4
View File
@@ -101,18 +101,32 @@ def is_proc_running(pid, name=None):
proc = subprocess.Popen(["C:\\Windows\\System32\\findstr", "%s" % pid],
stdin=proc_sub.stdout,
stdout=subprocess.PIPE, shell=False)
else:
elif platform.system() == "Linux":
# /bin/ps -ef | /bin/grep -v grep | /bin/grep -w pid
proc_sub = subprocess.Popen(["ps", "-ef"],
proc_sub = subprocess.Popen(["/bin/ps", "-ef"],
stdout=subprocess.PIPE,
shell=False)
proc_v_sub = subprocess.Popen(["grep", "-v", "grep"],
proc_v_sub = subprocess.Popen(["/bin/grep", "-v", "grep"],
stdin=proc_sub.stdout,
stdout=subprocess.PIPE,
shell=False)
proc = subprocess.Popen(["grep", "-w", "%s" % pid],
proc = subprocess.Popen(["/bin/grep", "-w", "%s" % pid],
stdin=proc_v_sub.stdout,
stdout=subprocess.PIPE, shell=False)
elif platform.system() == "Darwin":
# /bin/ps -ef | /bin/grep -v grep | /bin/grep -w pid
proc_sub = subprocess.Popen(["/bin/ps", "-ef"],
stdout=subprocess.PIPE,
shell=False)
proc_v_sub = subprocess.Popen(["/usr/bin/grep", "-v", "grep"],
stdin=proc_sub.stdout,
stdout=subprocess.PIPE,
shell=False)
proc = subprocess.Popen(["/usr/bin/grep", "-w", "%s" % pid],
stdin=proc_v_sub.stdout,
stdout=subprocess.PIPE, shell=False)
else:
raise Exception("Unknown system environment.")
(out, _) = proc.communicate()
out = get_decode(out).strip()
LOG.debug("check %s proc running output: %s", pid, out)
+5 -2
View File
@@ -117,9 +117,12 @@ def is_proc_running(pid, name=None):
if platform.system() == "Windows":
list_command = ["C:\\Windows\\System32\\tasklist"]
find_command = ["C:\\Windows\\System32\\findstr", "%s" % pid]
elif platform.system() == "Darwin":
list_command = ["/bin/ps", "-ef"]
find_command = ["/usr/bin/grep", "%s" % pid]
else:
list_command = ["ps", "-ef"]
find_command = ["grep", "%s" % pid]
list_command = ["/bin/ps", "-ef"]
find_command = ["/bin/grep", "%s" % pid]
proc = _get_find_proc(find_command, list_command)
(out, _) = proc.communicate()
out = get_decode(out).strip()