2

I need to check if my Qt GUI application is already running in the current X session. That is, I want to forbid running several instances of it. But running several instances by different users or by the same user on another (i.e. remote) X server should be allowed.

How can this be done?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Michael
  • 903
  • 1
  • 8
  • 16

2 Answers2

9

Qt has already a solution to single instance per user: QtSingleApplication. Check if this suits you.

handle
  • 5,859
  • 3
  • 54
  • 82
Marcin Gil
  • 68,043
  • 8
  • 59
  • 60
0

Create a dotfile (say, ~/.yourapp-xsessionID) when launching the program, and delete it when exiting; it the file already exists (i.e. it's already running) print out an error message and exit.

For the problems with this approach, see Firefox.

janneb
  • 36,249
  • 2
  • 81
  • 97