[Interest] Preventing Multiple Instances of EXE

Jérôme Godbout jerome at bodycad.com
Fri Apr 22 21:22:13 CEST 2016


Take care which mecanism you use here, this get really annoying with some
crashing application (not only they crash, but to refuse to launch again).

To avoid this, simply use a pid file and check if the pid process still
run, give option to your user to kill the previous instance of the program
(in case the process is hook or is zombie). If the pid process does not
exist, assume none is launch and put your pid into the file.This way you
don't get your user mad and control the number of instance.

Take care, if you want to allow application to run 1x/machine or 1x/user
connected. The 1x/user will require to either create the pid file into the
user home directory or use the user identifier into the pid file.

Jerome

On Fri, Apr 22, 2016 at 3:11 PM, Nye <kshegunov at gmail.com> wrote:

> Hello,
> This is ordinarily done with the help of a global locking primitive (for
> example a global mutex). On the first run the mutex would be locked, and if
> locking fails on the second one, you just exit the application.
> IMPORTANT: As any global resource, special care should be taken to release
> it in case of expected or unexpected program shutdown.
>
> As for a Qt-way of doing this, you could try QSystemSemaphore (
> http://doc.qt.io/qt-5/qsystemsemaphore.html).
>
> Kind regards.
>>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160422/2a716792/attachment.html>


More information about the Interest mailing list