Nyaruko
Nyaruko

Reputation: 4459

Qt under linux, how to detect a process is already running?

I am developing under ubuntu 16.04. The issue I run into is: I want to detect whether the user has already started the application, if yes, it exits directly.

I have tried using QLocalServer, QSharedMemory to achieve that. But the problem is:

If the program crash without properly close the local server or destroy the shared memory, the local socket/shared memory will remain in the OS and prevent the user to launch the program again.

How to deal with this?

Upvotes: 1

Views: 507

Answers (1)

Benjamin T
Benjamin T

Reputation: 8311

For the shared memory issue you could take a look at this question QSharedMemory is not getting deleted on Application crash

For a more generic answer about having a single instance of an application, you can take a look at Qt Single Application which is part of qt-solutions

Upvotes: 2

Related Questions