From: Phillip Gawlowski Date: 2010-12-05T19:39:19+09:00 Subject: Re: How to tell if ruby app is already running On Sun, Dec 5, 2010 at 12:19 AM, Daniel Berger wrote: > On 12/4/10 2:47 PM, Jim Burgess wrote: >> >> Hi, >> >> I have a FXRuby app, which is fine and dandy and does exactly what it >> should. However, if the user, for whatever reason, decides to start two >> instances of the app, bad things start happening. >> My question: is there any way for my app to check if another instance of >> itself is running before launching itself? > > To make sure no more than 1 instance of the script is running: > > gem install posixlock > require 'posixlock' > DATA.posixlock( File::LOCK_EX | File::LOCK_NB ) This smells like a pure UNIX solution to me (and I don't know if Ruby can deal with the Windows POSIX subsystem, as that is something that isn't part of the default install on Windows). What I would do is create a file in the app's startup code (in the temporary directories of the OSes you target, for example, since that directory gets cleaned rather often by the OS itself), and check if this file exists on start up. Of course, you get a problem if your application is killed by a task manager (so, you could write the PID of your current process into the lock file, and check if this PID exists before you terminate your app prematurely). -- Phillip Gawlowski Though the folk I have met, (Ah, how soon!) they forget When I've moved on to some other place, There may be one or two, When I've played and passed through, Who'll remember my song or my face.