I have a script that looks like this. Invoked with ./myscript.sh start
#!/bin/bash
if [[ "$1" == "start" ]]; then
echo "Dev start script process ID: $$"
cd /my/path1
yarn dev &> /my/path/logs/log1.log &
echo "started process1 in background"
echo "Process ID: $!"
echo "Logging output at logs/log1.log"
sleep 2
cd /my/path2
yarn start:dev &> /my/path/logs/log2.log &
echo "started process2 in background"
echo "Process ID: $!"
echo "Logging output at logs/log2.log"
sleep 2
cd /my/path2
yarn dev &> /my/path/logs/log3.log &
echo "started process3 in background"
echo "Process ID: $!"
echo "Logging output at logs/log3.log"
elif [[ "$1" == "stop" ]]; then
killList=`ps | grep node | awk '{print $1}'`
if [[ $killList != "" ]]; then
echo $killList | xargs kill
echo "Processes killed: $killList"
else
echo "Nothing to stop"
fi
else
echo "Invalid argument"
fi
When i run ps after I run this script, i can see a bunch of node processes (more than 3) that I assume has been started by the yarn dev commands. I want to run ./myscript.sh stop and stop all the node processes that were spawned from my previous run of ./myscript.sh start
How do I make this happen?
killall nodeand was able to work it out till here (the elif block)nodeprocess? Do you just want to kill all runningnodeprocesses irrespective of who started them? Are you just looking forkillall nodeorpkill node?