From 1bb15765eda1a82b580d07f8a690fb5b55fe16cd Mon Sep 17 00:00:00 2001 From: Maxim Karasev Date: Thu, 24 Jun 2021 02:52:37 +0300 Subject: [PATCH] pmb.helpers.run_core.kill_commands: use minimal subset of ps parameters (MR 2074) again, busybox ps supports only -o option (-e is ignored, because busybox always shows all processes). --- pmb/helpers/run_core.py | 4 ++-- test/test_run_core.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pmb/helpers/run_core.py b/pmb/helpers/run_core.py index d2a6c479..9609f89d 100644 --- a/pmb/helpers/run_core.py +++ b/pmb/helpers/run_core.py @@ -110,10 +110,10 @@ def kill_command(args, pid, sudo): :param pid: process id that will be killed :param sudo: use sudo to kill the process """ - cmd = ["ps", "-e", "-o", "pid=,ppid=", "--noheaders"] + cmd = ["ps", "-e", "-o", "pid,ppid"] ret = subprocess.run(cmd, check=True, stdout=subprocess.PIPE) ppids = [] - proc_entries = ret.stdout.decode("utf-8").rstrip().split('\n') + proc_entries = ret.stdout.decode("utf-8").rstrip().split('\n')[1:] for row in proc_entries: items = row.split() if len(items) != 2: diff --git a/test/test_run_core.py b/test/test_run_core.py index 99fbfbbe..7adeb6d9 100644 --- a/test/test_run_core.py +++ b/test/test_run_core.py @@ -98,16 +98,16 @@ def test_foreground_pipe(args): # The first command uses ps to get its process group id (pgid) and echo it # to stdout. All of the test commands will be running under that pgid. cmd = ["sudo", "sh", "-c", - "pgid=$(ps -p ${1:-$$} -o pgid=);echo $pgid | tr -d '\n';" + + "pgid=$(ps -o pgid= | grep ^${1:-$$});echo $pgid | tr -d '\n';" + "sleep 10 | sleep 20 | sleep 30"] args.timeout = 0.3 ret = func(args, cmd, output_return=True, output_timeout=True, sudo=True) pgid = str(ret[1]) - cmd = ["ps", "-e", "-o", "pgid=,comm=", "--noheaders"] + cmd = ["ps", "-e", "-o", "pgid,comm"] ret = subprocess.run(cmd, check=True, stdout=subprocess.PIPE) - procs = str(ret.stdout.decode("utf-8")).rstrip().split('\n') + procs = str(ret.stdout.decode("utf-8")).rstrip().split('\n')[1:] child_procs = [] for process in procs: items = process.split(maxsplit=1)