Preventing multiple processes?

BlitzMax Forums/BlitzMax Programming/Preventing multiple processes?

JoshK(Posted 2010) [#1]
Here's my attempt:
http://blitzmax.com/codearcs/codearcs.php?code=2787

Is there a better way to do this?

It looks like Brucey has some pretty advanced interprocess stuff going. I'm not sure how mutexes relate to separate processes.


Zeke(Posted 2010) [#2]



JoshK(Posted 2010) [#3]
Do you have some cross-platform code? I believe bah.interprocess might do it, but I'm not sure how.


Zeke(Posted 2010) [#4]
this use bah.interprocess mod:

SuperStrict

Import bah.interprocess

Local mutex:TNamedMutex = New TNamedMutex.Create(OPEN_OR_CREATE , "app")

If Not mutex.trylock()
	Notify "Process already running"
	End
EndIf

Notify "App started"

TNamedMutex.remove("app")


Last edited 2010


JoshK(Posted 2010) [#5]
The mutex will stay in memory after the program ends, unless it is removed by the program, right? So if the app crashes, another instance won't be able to start? I got around this problem by updating a value every 20 seconds with the system time, but this isn't a very reliable solution. Is there a better way?

Last edited 2010


Czar Flavius(Posted 2010) [#6]
Why do you want to do this? Prevent cheating? Don't ban multiple instances of your game just for the sake of it! Sometimes it's fun.


xlsior(Posted 2010) [#7]
Why do you want to do this?


One benefit of only allowing a single copy is that you won't end up with 10 copies fighting over resources when the program didn't pop up instantaneously on a slowish computer, and people get impatient and keep clicking the icon.

Unfortunately not an uncommon scenario.


JoshK(Posted 2010) [#8]
Why do you want to do this? Prevent cheating? Don't ban multiple instances of your game just for the sake of it! Sometimes it's fun.

It's to prevent multiple instances of a program from trying to modify files at once.

Last edited 2010