Program-wrapper to avoid multiple running instances
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > Program-wrapper to avoid multiple running instances




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Program-wrapper to avoid multiple running instances  
norman@unnu.org


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-18-06 03:40 AM

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






[ Post a follow-up to this message ]



    Re: Program-wrapper to avoid multiple running instances  
Bit Twister


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-18-06 03:40 AM

On 16 Feb 2006 08:46:24 -0800, norman@unnu.org wrote:
> 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?

man pgrep
man ps
man grep

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






[ Post a follow-up to this message ]



    Re: Program-wrapper to avoid multiple running instances  
Doug Freyburger


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-18-06 03:40 AM

Bit Twister wrote:
> norman@unnu.org wrote:
> 
> 
> 
>
> man pgrep
> man ps
> man grep

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.






[ Post a follow-up to this message ]



    Re: Program-wrapper to avoid multiple running instances  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-18-06 03:40 AM

2006-02-16, 08:46(-08), norman@unnu.org:
> 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
[...]

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

Generally something called "start-stop-daemon".

--
Stéphane





[ Post a follow-up to this message ]



    Re: Program-wrapper to avoid multiple running instances  
norman@unnu.org


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-19-06 10:50 PM

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

> Generally something called "start-stop-daemon".

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.






[ Post a follow-up to this message ]



    Re: Program-wrapper to avoid multiple running instances  
norman@unnu.org


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-19-06 10:50 PM

> 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?

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.

> 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.

That's exactly what i was thinking of!






[ Post a follow-up to this message ]



    Re: Program-wrapper to avoid multiple running instances  
Doug Freyburger


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-20-06 01:47 AM

norman@unnu.org wrote:
> Doug Freyburger 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.

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.






[ Post a follow-up to this message ]



    Re: Program-wrapper to avoid multiple running instances  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-20-06 12:48 PM

2006-02-19, 15:30(-08), norman@unnu.org: 
> 
>
> I don't want to run it as a daemon process.

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 <marekm@i17linuxb.ists.pwr.wroc.pl>, public domain.
[...]

--
Stéphane





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:06 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register