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?

Nyaruko
  • 4,329
  • 9
  • 54
  • 105
  • 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. – nwp Mar 25 '17 at 07:11
  • But it seems this is common phenomenon for Qt under Linux... Just wonder is there any workaround? – Nyaruko Mar 25 '17 at 08:30
  • 1
    In what way is the file workaround insufficient? – nwp Mar 25 '17 at 08: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? – Nyaruko Mar 25 '17 at 09:06
  • @nwp The thing with opening a file for writing is not true in linux. – Jonas Schäfer Mar 25 '17 at 12:15

1 Answers1

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

Community
  • 1
  • 1
Benjamin T
  • 8,120
  • 20
  • 37