Tyler Littlefield wrote:
> why would you need a mutex? just check through the process list.
>   

Using a mutex is the more "correct" solution.

1. Mutexes do not rely on the program name: if someone manipulates the 
files for your program, it may not be able to detect a duplicate 
instance based on the process list.
2. Mutexes are useful for more than instance checking: it provides a 
foundation for additional functionality if it is every required, even 
across completely different programs.
3. Mutexes are more atomic, and there are fewer layers of code. If an 
instance is defunct but has released its mutex, then another instance 
will be able to run and will require less user intervention.

In general, I try to avoid messing with process lists or manipulating 
user-visible operating system state. Even in Linux, you would be better 
off relying on a locking mechanism (an anchor file in /tmp, for example) 
if Linux does not provide something similar to a mutex (I am not 
familiar with the POSIX API so I cannot say if it does or does not).

-- 
John Gaughan

Reply via email to