[Qt-interest] A couple of Issues in Qt Application

Dan Mills dmills at exponent.myzen.co.uk
Fri Oct 30 03:07:32 CET 2009


The Unix way of doing this is to create a 'lock' file containing the PID
of the process, then on startup, check if the lockfile exists, if it
does, check to see if the PID refers to a copy of your program. 

The second check ensures that a crash will not prevent a new copy
starting.

I would note that you want to think carefully about single instance
programs that are not daemons given that unix is by design multi user,
for true 'one running instance per system' (which usually means a system
daemon or similar), the lock files typically end up in /var/run/, for
things that should be one instance per user, ~/.appname.lock is fairly
conventional, but think long and hard about why you want single instance
here, it tends to cause cursing sooner or later. 

HTH.

Regards, Dan.





More information about the Qt-interest-old mailing list