Stop two of same game loading at once on Mac

BlitzMax Forums/BlitzMax Programming/Stop two of same game loading at once on Mac

Grey Alien(Posted 2007) [#1]
Hiya, on the PC I am able to create a Mutex in memory once my game has loaded and thus if someone tries to load another copy, the second copy can auto-shut down. Is there a way to do this on the Mac please?

Thanks!


jhans0n(Posted 2007) [#2]
I can't find a way to launch two copies of my game on the Mac without copying the executable. If I double-click the icon in Finder, it just brings me to the existing running copy of the game.

So, if you're trying to protect against people accidentally launching two copies, I'm not sure it's an actual problem on this platform. If you're trying to protect against them doing something intentional, that's a different story.


Grey Alien(Posted 2007) [#3]
Ah Cool, so it's a non-issue Thanks!


FlameDuck(Posted 2007) [#4]
Create a lock file. Works on all platforms. Except maybe Windows.


Grey Alien(Posted 2007) [#5]
I forgot to test it on my Mac. But yeah it fails I can do that nice and simple.


ImaginaryHuman(Posted 2007) [#6]
I agree with Flameduck I'd go with writing a temporary file then if that file exists already you shut down the app.


xlsior(Posted 2007) [#7]
Except one big problem with lock files is that they can be problematic if the first instance of the game crashes or quits without removing the lock file (power interruption, Os crash, etc.)
then trying to re-launch the game will fail until you manually remove the lock file, or do some other magic first to make sure there isn't already another copy running... And if you can do that, there's no need for the lock file in the first place. :-?


Winni(Posted 2007) [#8]
And when your application crashes unexpectedly without deleting the temp file first, your application will never start again...

Actually, for GUI apps on the Mac the entire thing is a non-issue since the OS won't let you start the same app twice. Only command line tools can be launched more than once.

In any case, checking the process list for multiple appearances of the same app would be the safe way to do it.

Alternatively, you can "play" with sockets, too. Let your app first try to connect to a port on localhost; if a server responds, you know that your app has already been launched and the new instance ends. If there is no response, your app actually becomes the server and proceeds running. In theory that should work.


Dreamora(Posted 2007) [#9]
another alternative would be shared memory


Grey Alien(Posted 2007) [#10]
I knew there was a reason I used a Mutex on the PC.


Winni(Posted 2007) [#11]
Grey, I'm not getting it - this really is non-issue on the Mac. You just cannot start the same .app twice on OS X, so it's already been taken care of for you.


Grey Alien(Posted 2007) [#12]
Yep thanks I realise hense my
Ah Cool, so it's a non-issue Thanks!
post :-)


FlameDuck(Posted 2007) [#13]
And when your application crashes unexpectedly without deleting the temp file first, your application will never start again...
Yes, well that's the downside of using a poor OS/filesystem that doesn't allow you to create "O_EXCL" type atomic files. From what I understand though MacOS does.

I knew there was a reason I used a Mutex on the PC.
Well yes. See above.


Grey Alien(Posted 2007) [#14]
confirmed that this is a non-issue by testing myself.