Page 1 of 1
Detecting Program Instances
Posted: 24.09.2004, 22:46
by Rassilon
Is it possible using C++ and freeglut/glut/OpenGL NO WinMain to detect if the same program is loaded twice? If so how is it done?
Posted: 25.09.2004, 14:47
by selden
A crude but common method is to create a temporary file (called a lock file) that's deleted when the program exits.
That file can contain whatever information you want, like the time the program started and/or info that's specific to the operating system, like the process id number.
Deleting a lock file when the program exits can be tricky sometimes, since your program has to be able to trap all of the ways the user might use to terminate the program. Even so, programs that use them have to provide for cases when lock files accidentally weren't deleted, maybe because the program or computer crashed. This is often handled by asking the user if the program should run anyhow.
Posted: 25.09.2004, 18:21
by Rassilon
Damn why didnt I think of that lol...Thanks selden...Of course if there is a full proof method someone knows about please let me know...
Posted: 26.09.2004, 09:22
by hjw
Well, on unix systems I use locking functions. The locks are *unlocked*
automatically by the OS as soon as the locking process terminates.
So you don't have to fool around with all the possible ways a process
might terminate (works even if it crashes).
Having no experience at all with windows, I can only suggest looking
for the POSIX "lockf" function.
MfG - Horst
Posted: 27.09.2004, 03:51
by Rassilon
Yeah theres a DOS equavilant that locks a file. This would work in cunjunction with seldens method to prevent another program from accessing the same config file...but if I understand your approach you are referring to locking the actual application? I looked up lockf its similar to lock/locking in ANSI C...
So what I would need a full proof method that would access the processes currently running and read the list...In that list if it detects the equivalent of argc[0] which if you program C is the name of the program...So how would I access the processes table or a list of all running progams as a directory dump would?