I can run multiple instances of a bash script in the background and everything is great. I have it setup in such way that some have -x
as a flag and some not. See:
./test.sh &
./test.sh &
./test.sh -x &
./test.sh -x &
Now, I want to kill all scripts that were run with the -x
flag. I always kill scripts running in the background using this:
ps -aux | grep -Po "^S{1,}s*Kd*(?=.*test.sh$)" |
while read -r level
do
kill $level
done
However, ps -aux
doesn't show any arguments/flags that were given when the script was run. So when using that, I can't only grab the scripts that were run with -x
. Is there a solution to this? I want to only kill the background scripts that were run with -x
.