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).
This commit is contained in:
Maxim Karasev 2021-06-24 02:52:37 +03:00 committed by Alexey Min
parent 31e7a0006d
commit 1bb15765ed
No known key found for this signature in database
GPG Key ID: EBF5ECFFFEE34DED
2 changed files with 5 additions and 5 deletions

View File

@ -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:

View File

@ -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)