Find the answer to your Linux question:
Results 1 to 2 of 2
hello OS: CENTOS 5 How to detect/prevent running the multiple instance of same application, in c++ code. My applicaion is written in c++. and compile using the g++ version 4.1.2. ...
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Posts
    15

    How to prevent/detect running multiple instance of same application/dameon

    hello

    OS: CENTOS 5
    How to detect/prevent running the multiple instance of same application, in c++ code.

    My applicaion is written in c++. and compile using the g++ version 4.1.2.

    Thanks in advance.
    Ritesh

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    In your program, create a file in the /tmp directory. Use advisory locking to lock, say, the first byte in the file. If the lock succeeds, then the application should continue running. If it fails, then the application should exit.

    For information on advisory locking, do this at the command line:
    Code:
    man fcntl
    If man pages are not installed on your system, google this:
    Code:
    linux man fcntl
    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...