Another Run-Time Instance Running?

QUESTION: How do I tell if another instance of my IDL application is already running? I'm talking about a run-time application that I build into a .sav file, which starts more or less like an executable when I double-click its icon. If I then double-click the same icon again, I do not want to run another instance. I want to check to see if the application is already running, and just bring it to the front of the display or to the attention of the user.

I am aware of the XRegistered trick, in which a widget program can check to see if a program with that name has already been registered with the window manager. This works fine from within a single IDL session, but does not work in the scenario I am describing, probably because the two programs are running in different IDL sessions. Any ideas?

ANSWER: One way to handle this kind of interprocess communitation is to use the semaphore routines in IDL (SEM_Create, SEM_Lock, SEM_Delete, and SEM_Release). From the IDL documentation:

A semaphore is a software mechanism used to provide synchronization between multiple processes or between different threads of a single process. Often, semaphores are used to protect or restrict access to shared or key resources, such as shared memory segments.

The first routine to start can create and lock a semaphore that can then be checked by subsequent routines. If they find the semiphore locked, they can exit without creating the graphical user interface part of the program.

Another possible solution is to use a shared memory segment, using the SHMMAP routine in IDL, to include an IDL variable that will indicate that an instance of this program is already running.

Version of IDL used to prepare this article: IDL 7.1.

Google
 
Web Coyote's Guide to IDL Programming