Linux shell scripts: how can I stop the first program when the second is finished?

I have two programs on Linux (e.g. shell scripts):

NeverEnding.sh
AllwaysEnds.sh

the first one never stops , so I want to run it in background .
the second stops without problems.

I would like to make a Linux shell script that calls them like , but automatically stops (for example, kills) the first when the second ends .

If necessary, special command line tools are allowed.

+4
source share
1 answer

& PID $!. , , , :

#!/bin/bash

NeverEnding.sh &
pid=$!

AllwaysEnds.sh

kill $pid

pid , $! , .

+5

Source: https://habr.com/ru/post/1534175/


All Articles