I have a bash script which I think is making a false assumption.
The bash script is as shown:
running()
{
if
test -e .pid
then
pid=`cat .pid`
if
ps -p $pid | grep -q $pid
then
return 0
fi
fi
return 1
}
dd=`date +'%d'`
if
running
then
echo Still running PID:
cat .pid
else
echo $$ > .pid
echo Current PID: $$
java -cp ./runLoad2.jar:$CLASSPATH runLoad.mainClass
fi
In my opinion the above bash shell script is making a false assumption while checking if the process id is still active or not.
Here while starting for the first time there is no .pid file so it creates the file and stores the pid in the .pid file.
The second time on wards it checks if the process id stored in the .pid file is active or not and if it is inactive or if the ps commad does not return any input it starts the java program.
But here after the first load is complete the pid is released back to os and when the shell script runs for the second time it uses the old pid which can be used by some other process and this is where I think its making a false assumption thinking that the stored process id always refers to this shell script.
I'm not sure if I'm correct. Can someone clarify.