I've couple instances of script.sh running in parallel, doing the same thing, running in background.
I'm trying to use a function to kill all the current running scripts when executed.
So, for example, ./script.sh -start will start the script (which I can run few in parallel) and when I execute ./script.sh -kill will kill all instances of the script.
f() {
procName=`basename $0`
pidsToKill=`ps -ef | grep $procName | grep -v grep | awk '{ print $2 }'`
if [[ $pidsToKill ]]; then
for i in $pidsToKill; do
kill -9 $i
done
echo "Killed running scripts."
else
echo "No opened scripts to kill"
fi
}
For some reason, sometimes it kill couple of the scripts and sometimes returns an error.
I've figured a way to solve this, but I want to understand why this one doesn't work. Any ideas?
less myprogramname/README
, and other unrelated processes. Don't do this.