preventing execution of same executable

Discussion in 'C' started by priyatendulkar, Mar 6, 2012.

  1. priyatendulkar

    priyatendulkar New Member

    Joined:
    Jun 20, 2011
    Messages:
    20
    Likes Received:
    1
    Trophy Points:
    0
    Hi ,

    I have an executable say a.out.

    My requirement is that ..At a time only single instance of a.out be executed

    Is that possible in linux
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    I don't think you can prevent the OS launching a second copy of the executable but you can make them detect each other. For example one way is to create a file lock when the executable starts, so if a second instance is launched, it would try to lock that file, fail, deduce from that that there is already someone else running and exit.
     
  3. priyatendulkar

    priyatendulkar New Member

    Joined:
    Jun 20, 2011
    Messages:
    20
    Likes Received:
    1
    Trophy Points:
    0
    k..
    Thanx a lot for the response
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice