Results 1 to 20 of 30

Thread: Limiting the number of instances of one application

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2006
    Location
    Mexico City
    Posts
    31
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Limiting the number of instances of one application

    Quote Originally Posted by Chicken Blood Machine View Post
    A quick and dirty cross-platform solution would be to create a 'lock' file at startup and delete the file at shutdown. Any new instances check if the file exists first before continuing.

    This isn't foolproof, since if your app crashes, you will have to delete the file manually.
    IMO this is the best solution, easy and clean. It works for all platforms, it can be instrumented through the net, or locally, it can be a counter to limit number of applications...

    Simple is, in many cases, the best solution...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Limiting the number of instances of one application

    Quote Originally Posted by arnaiz View Post
    Simple is, in many cases, the best solution...
    It has its strong disadvantages. There is really no way telling if the lock file is stale or not. Under Windows you can easily use a file to make a singleton application by demanding a mandatory lock on the file. On the other hand I don't know if the lock will be released when the app gets killed. So a solution is easy but the drawback is that you might not be able to restart the application after a crash. The same goes with files holding pids of processes. You can never be sure if the lock file is stale or not and eventually you have to guess (for example by trying to find the process in the process table) or ask the user (like for example kmail does). So simple is easy to implement, but can fail as easily.

  3. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Limiting the number of instances of one application

    Mixing kinda lock file and TCP connection is definitely the best slution IMO. I'm attaching the source I've come to. It can lock the application to whatever number of instances wanted and can send messages to the first created instances (this is a limitation I didn't managed to fix with the current design so I'm working on a new version...)

    Well actually I can't attach my file (too much already attached by me on other posts : I'm waiting for an answer from the admins and will attach it ASAP )
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2006, 18:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.