简体   繁体   中英

Start and stop multiple processes at once (Ubuntu)

so I have a bunch of mixed scripts on my Ubuntu server which I would like to run all at once, keep the PID so i can kill them all at once. They are mixed ruby and python scripts, which shouldn't matter since it would just be a list of commands to run and save the PID of, I just don't know how. And would it possible to have the script as ./script start|stop|restart?

Thanks

have all scripts running from shell script

vi Main.sh

#/bin/ksh

MODE=$1

if [ $MODE = "start" ]; then
#get PID of main sacript
echo " Main PID: $!" >> PID.txt

#Run first script
./script1.sh &
#save PID of script one
echo "script 1 PID: $!" >> PID.txt

#Run second script
./script2.sh &
#save PID of script one
echo "script 2 PID: $!" >> PID.txt

and so on...

fi

if [ $MODE = "stop" ]; then

Total_PID=`wc -l PID.txt|cut -d " " -f1`
x=1

while [ $x -le $Total_PID ]
do
PID=`sed -n ${x}p PID.txt|awk -F ":" '{print $2}'`
kill -9 $PID
let x=$x+1
done


fi

this is just an idea...you can modify this according to your requirement and this may have some syntax error (as this is not tested and its pesdocode)...please correct it... you will run this script as

./Main.sh start

or

./Main.sh stop

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM