Professional Web Applications Themes

Program-wrapper to avoid multiple running instances - Linux / Unix Administration

Hello, i am looking for a simple wrapper, that checks if an instance of the wrapped program is already running. Something like this: $ wrapper -p /path/to/pid/file /my/program If an instance is already running the wrapper program should exit quitely. Any suggestions? Norman...

  1. #1

    Default Program-wrapper to avoid multiple running instances

    Hello,
    i am looking for a simple wrapper, that checks if an instance of the
    wrapped program is already running. Something like this:

    $ wrapper -p /path/to/pid/file /my/program

    If an instance is already running the wrapper program should exit
    quitely.

    Any suggestions?

    Norman

    norman@unnu.org Guest

  2. #2

    Default Re: Program-wrapper to avoid multiple running instances

    On 16 Feb 2006 08:46:24 -0800, org wrote: 

    man pgrep
    man ps
    man grep

    and for some scripting doentation
    ! bash script introduction doentation
    http://tldp.org/LDP/intro-linux/html/index.html
    ! bash script advanced doentation
    http://tldp.org/LDP/abs/html/index.html

    Bit Guest

  3. #3

    Default Re: Program-wrapper to avoid multiple running instances

    Bit Twister wrote: 


    >
    > man pgrep
    > man ps
    > man grep[/ref]

    Some programs already record their PID for this purpose so
    it is a well known method. Having a wrapper program to
    generalize it to everyone is a great idea. Rather than doing
    it is a one-off shell script, are you interested in doing it in
    C or C++ or whatever and delivering to to one of the free
    software foundations?

    Get the PID out of the file, see if that PID is running. If
    not launch the specified program, get its PID, record it
    in the file. Exit leaving the program daemon-ized.

    Doug Guest

  4. #4

    Default Re: Program-wrapper to avoid multiple running instances

    2006-02-16, 08:46(-08), org: 
    [...]

    Most Linux distributions have such things. Probably other
    systems as well.

    Generally something called "start-stop-daemon".

    --
    Stéphane
    Stephane Guest

  5. #5

    Default Re: Program-wrapper to avoid multiple running instances

    > Most Linux distributions have such things. Probably other 
     

    I don't want to run it as a daemon process. Just as simple as i
    described before: A wrapper, that only runs a programm if it is not
    already running. This should help to avoid to start multiple long
    running tasks of the same kind.

    norman@unnu.org Guest

  6. #6

    Default Re: Program-wrapper to avoid multiple running instances

    > Some programs already record their PID for this purpose so 

    If a had strong experiences in programming C or C++, i would do it. But
    i am more a Ruby guy coming from the web-development world. So maybe
    someone else could do this simple job.
     

    That's exactly what i was thinking of!

    norman@unnu.org Guest

  7. #7

    Default Re: Program-wrapper to avoid multiple running instances

    org wrote: 
    >
    > If a had strong experiences in programming C or C++, i would do it. But
    > i am more a Ruby guy coming from the web-development world. So maybe
    > someone else could do this simple job.[/ref]

    My point was it doesn't take strong skills for such a small
    project. It's a perfect starter program for someone who
    doesn't already have experience in the specific language.
    it's going to be under 50 lines. About the size of the typical
    homework assignment for a week in an undergrad programming
    course. If you've done whatever Ruby is, you have enough
    knowledge of developement to use your experience as a
    base to build upon.

    Doug Guest

  8. #8

    Default Re: Program-wrapper to avoid multiple running instances

    2006-02-19, 15:30(-08), org: 

    >
    > I don't want to run it as a daemon process.[/ref]

    What do you mean?

    In which way don't you want it to be started as a daemon?
    A daemon is called "daemon" usually by the nature of what it
    does. There's no special way to start a daemon. That's some
    process that runs on the /background/ and whose actions can be
    invoked by other means that terminal interaction.

    start-stop-daemon won't do anything special to start the
    program, if you don't use the --background option.

    If you use the --background option, it will detach the process
    from the current terminal and its parent process, and have its
    stdin/stdout/stderr point to /dev/null, which is a sensible
    thing to do if that process is running in the background
    independently of any terminal.

    So

    start-stop-daemon -Sbvmp /var/pid/sleep.pid -x /bin/sleep -- 100

    will start sleep in background detached from the terminal.

    start-stop-daemon -Svmp /var/pid/sleep.pid -x /bin/sleep -- 100 &

    will start sleep as a background job of the current terminal (if
    the shell supports job control). That will be the same as:

    /bin/sleep 100 &

    except for the handling of the pid file.

    This, above is for the start-stop-debian found on debian, I
    guess it's the same for other distribution.

    $ start-stop-daemon --version
    start-stop-daemon 1.13.13
    $ start-stop-daemon --help
    start-stop-daemon VERSION for Debian - small and fast C version written by
    Marek Michalkiewicz <ists.pwr.wroc.pl>, public domain.
    [...]

    --
    Stéphane
    Stephane Guest

  9. #9

    Default Re: Program-wrapper to avoid multiple running instances [SOLVED]

    Stephane CHAZELAS schrieb:
     
    > > 
    > >
    > > I don't want to run it as a daemon process.[/ref]
    >
    > What do you mean?
    >
    > In which way don't you want it to be started as a daemon?
    > A daemon is called "daemon" usually by the nature of what it
    > does. There's no special way to start a daemon. That's some
    > process that runs on the /background/ and whose actions can be
    > invoked by other means that terminal interaction.
    >
    > start-stop-daemon won't do anything special to start the
    > program, if you don't use the --background option.
    >
    > If you use the --background option, it will detach the process
    > from the current terminal and its parent process, and have its
    > stdin/stdout/stderr point to /dev/null, which is a sensible
    > thing to do if that process is running in the background
    > independently of any terminal.
    >
    > So
    >
    > start-stop-daemon -Sbvmp /var/pid/sleep.pid -x /bin/sleep -- 100
    >
    > will start sleep in background detached from the terminal.
    >
    > start-stop-daemon -Svmp /var/pid/sleep.pid -x /bin/sleep -- 100 &
    >
    > will start sleep as a background job of the current terminal (if
    > the shell supports job control). That will be the same as:
    >
    > /bin/sleep 100 &
    >
    > except for the handling of the pid file.
    >
    > This, above is for the start-stop-debian found on debian, I
    > guess it's the same for other distribution.
    >
    > $ start-stop-daemon --version
    > start-stop-daemon 1.13.13
    > $ start-stop-daemon --help
    > start-stop-daemon VERSION for Debian - small and fast C version written by
    > Marek Michalkiewicz <ists.pwr.wroc.pl>, public domain.
    > [...][/ref]

    After reading your post, i realized that it was exactly what i was
    looking for. Thank you very much!

    Norman

    norman@unnu.org Guest

Similar Threads

  1. Replies: 10
    Last Post: February 23rd, 09:14 PM
  2. Draging multiple instances of multiple objects
    By equinox007 webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 2
    Last Post: January 23rd, 01:31 AM
  3. Running Instances on Windoz
    By Robert in forum Oracle Server
    Replies: 25
    Last Post: December 5th, 12:57 AM
  4. Checking number of instances running
    By Rene Scheibe in forum PERL Miscellaneous
    Replies: 2
    Last Post: August 7th, 10:46 PM
  5. 2 instances of windows explorer running
    By Rob in forum Windows XP/2000/ME
    Replies: 1
    Last Post: July 25th, 08:13 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139