This applies to any other app that runs under linux via java or any sort of wrapper.
Under System Monitor minecraft shows up as "java". this is problematic...
what if the java app that's running isn't minecraft. and what if there are several?
the best I've got for my script is :
if ps ax | grep -v grep | grep java > /dev/null
then
echo "Minecraft is running"
else
echo "Minecraft not running, run Minecraft to continue"
fiHow can I know for sure that Minecraft is running and not just any old java app?
Thanks
22 Answers
Firstly, when minecraft is running, run
pgrep -a javaNow find something unique, maybe it's just minecraft.
You will get your pid by running
pgrep -f minecraft 2 Really the best way to do this is to write out the PID to a file when you start it via shell script. Then you can send a 0 signal to the pid to see if it's currently running.
kill -0 $(cat /run/minecraft.pid)
This will return 0 if it's running, >0 (greater than 0) if it's not.
Otherwise, if you don't have control of the starting of the process, then a search like davidbaumann shows will mostly work.