Re: Ensure only single application instance.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Timothy Grant

    Re: Ensure only single application instance.

    On Fri, Aug 29, 2008 at 6:51 AM, Heston James <heston_james@l ive.co.ukwrote:
    Good afternoon all.
    >
    I have an application/script which is launched by crontab on a regular
    basis. I need an effective and accurate way to ensure that only one instance
    of the script is running at any one time.
    >
    After a short look around the internet I found a couple of examples, such as
    this one (http://code.activestate.com/recipes/474070/), however they both
    seem to be focused on a windows based environment.
    >
    Can anyone offer their advice on how best to do this on a linux based
    system?
    >
    I have been contemplating the idea of creating a pidfile which is destroyed
    at the end of the script, will this suffice? is it fool proof? My only
    concern with this is that if the script crashes or is stopped halfway
    through processing for whatever reason, I'll be left with a dead pidfile on
    the system and no successive runs will work.
    >
    I'm really interested to get your ideas guys, Thanks.
    >
    Heston
    >
    _______________ _______________ __
    Get Hotmail on your mobile from Vodafone Try it Now!
    --

    >
    Why not look at the process list, and if you find two entries kill the
    one that is just starting?


    --
    Stand Fast,
    tjg. [Timothy Grant]
  • Uberman

    #2
    Re: Ensure only single application instance.

    On Fri, Aug 29, 2008 at 6:51 AM, Heston James <heston_james@l ive.co.ukwrote:
    Good afternoon all.
    >
    I have an application/script which is launched by crontab on a regular
    basis. I need an effective and accurate way to ensure that only one instance
    of the script is running at any one time.
    You could create a named pipe in /tmp with a unique (static) name and
    permissions that disallow any kind of read/write access. Then simply have
    your script check for its existence when it starts. If it exists, then
    another instance of your script is running, and just terminate. Make sure
    your original instance removes the pipe when it exits.

    Comment

    • Cameron Laird

      #3
      Re: Ensure only single application instance.

      In article <dPZtk.60600$5p 1.41655@en-nntp-06.dc1.easynews .com>,
      Uberman <bhood37@hotmai l.comwrote:
      >On Fri, Aug 29, 2008 at 6:51 AM, Heston James <heston_james@l ive.co.ukwrote:
      >Good afternoon all.
      >>
      >I have an application/script which is launched by crontab on a regular
      >basis. I need an effective and accurate way to ensure that only one instance
      >of the script is running at any one time.
      >
      >You could create a named pipe in /tmp with a unique (static) name and
      >permissions that disallow any kind of read/write access. Then simply have
      >your script check for its existence when it starts. If it exists, then
      >another instance of your script is running, and just terminate. Make sure
      >your original instance removes the pipe when it exits.
      I'll write an article on this subject this fall. The
      essentials are:
      A. There's no canonical answer; every apparent solution
      has problems;
      B. The suggestions offered you are certainly among the
      popular ones;
      C. My personal favorite is to open a (network) socket
      server. For reasons I'll eventually explain, this
      has particularly apt semantics under Unix.

      Comment

      • Frank Millman

        #4
        Re: Ensure only single application instance.

        On Aug 29, 11:25 pm, Uberman <bhoo...@hotmai l.comwrote:
        On Fri, Aug 29, 2008 at 6:51 AM, Heston James <heston_ja...@l ive.co.ukwrote:
        Good afternoon all.
        >
        I have an application/script which is launched by crontab on a regular
        basis. I need an effective and accurate way to ensure that only one instance
        of the script is running at any one time.
        >
        The following is taken from the getmail FAQ -

        ------------------------------------------
        If you need to prevent two instances of getmail from running
        simultaneously, use any standard Unix method of providing a mutex for
        this purpose. One example would be to run getmail under a program like
        setlock (part of the daemontools package). Change your script or
        crontab file to invoke getmail like this:

        /path/to/setlock -n /path/to/lockfile /path/to/getmail [getmail
        options]

        There are other programs that provide functionality similar to
        setlock.
        ------------------------------------------

        HTH

        Frank Millman

        Comment

        • Larry Bates

          #5
          Re: Ensure only single application instance.

          Cameron Laird wrote:
          In article <dPZtk.60600$5p 1.41655@en-nntp-06.dc1.easynews .com>,
          Uberman <bhood37@hotmai l.comwrote:
          >On Fri, Aug 29, 2008 at 6:51 AM, Heston James <heston_james@l ive.co.ukwrote:
          >>Good afternoon all.
          >>>
          >>I have an application/script which is launched by crontab on a regular
          >>basis. I need an effective and accurate way to ensure that only one instance
          >>of the script is running at any one time.
          >You could create a named pipe in /tmp with a unique (static) name and
          >permissions that disallow any kind of read/write access. Then simply have
          >your script check for its existence when it starts. If it exists, then
          >another instance of your script is running, and just terminate. Make sure
          >your original instance removes the pipe when it exits.
          >
          I'll write an article on this subject this fall. The
          essentials are:
          A. There's no canonical answer; every apparent solution
          has problems;
          B. The suggestions offered you are certainly among the
          popular ones;
          C. My personal favorite is to open a (network) socket
          server. For reasons I'll eventually explain, this
          has particularly apt semantics under Unix.
          Cameron,

          I found this recipe (http://code.activestate.com/recipes/474070/) on
          ActiveState's site that had a working version of a single instance class for
          Windows that I've used quite successfully. Since I also work a lot Linux, I
          wrote and donated this version (http://code.activestate.com/recipes/546512/) for
          Linux that also seems to work well for me.

          -Larry

          Comment

          Working...