Bash linux: run multiple programs in parallel and stop everything when done

I am working on Ubuntu and I want to create a bash file that does the following:
Run one program (prog0) on kernel 1.
Wait 3 seconds.
Then write down processor and memory usage information for prog0 (I use two instances of pidstat for kernel 0 to register this information).
Then run another program (prog1) on kernel 0.
When prog1 has finished (I think prog1 will automatically exit), I would like to exit the entire previous process (prog0 and two pidstat).

taskset -c 1 prog0 -option0 &
sleep 3
taskset -c 0 pidstat 1 -C prog0 -u > log2 &
taskset -c 0 pidstat 1 -C prog0 -r > log3 &
taskset -c 0 prog1 -option1 > log1 

I do not know how to exit or kill all the processes that started when prog1 shuts down.

+5
source share
1

trap 'kill $(jobs -p)' EXIT

script. script.


script, :

#!/bin/bash
trap 'kill $(jobs -p)' EXIT
taskset -c 1 prog0 -option0 &
sleep 3
taskset -c 0 pidstat 1 -C prog0 -u > log2 &
taskset -c 0 pidstat 1 -C prog0 -r > log3 &
taskset -c 0 prog1 -option1 > log1

runme.sh.

: chmod +x runme.sh

, : ./runme.sh : ./runme.sh &

, taskset -c 0 prog1 -option1 > log1, script , .

+6

All Articles