1

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?

5
  • 2
    Your OS should be closing resources when your process dies, I suspect it just didn't completely die and is still in memory. Typically this is done by opening a specific file for writing, because only 1 process can do that at a time. Commented Mar 25, 2017 at 7:11
  • But it seems this is common phenomenon for Qt under Linux... Just wonder is there any workaround? Commented Mar 25, 2017 at 8:30
  • 1
    In what way is the file workaround insufficient? Commented Mar 25, 2017 at 8:34
  • 1
    @nwp, I have tried using QFile to open a file for writing. But its seems under linux, two process can write to the same file though? Commented Mar 25, 2017 at 9:06
  • @nwp The thing with opening a file for writing is not true in linux. Commented Mar 25, 2017 at 12:15

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.