Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Keep n instances running

by Anonymous Monk
on Jun 20, 2012 at 00:00 UTC ( [id://977173]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that runs on a server and performs some reporting and maintenance functions. I would like to ensure that there are always n instances of the script running. If an instance terminates unexpectedly I would like to start another instance to replace it. I will be doing this on Linux. What is the "right" way to accomplish this?

Replies are listed 'Best First'.
Re: Keep n instances running
by BrowserUk (Patriarch) on Jun 20, 2012 at 02:10 UTC

    Parallel::ForkManager could probably do that with half a dozen lines if you insist on using Perl; but isn't that a perfect use for inetd?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Re: Keep n instances running
by Anonymous Monk on Jun 20, 2012 at 02:16 UTC
Re: Keep n instances running
by tweetiepooh (Hermit) on Jun 20, 2012 at 14:48 UTC

    When ever I need to keep a job running I use a sub shell type structure

    #!(bash|ksh|sh) <set up environment> (while true do <perl script> # brief delay to ensure everything is shutdown sleep 60 done) &

    The subshell itself is backgrounded rather than just the Perl script.

    I'm sure this can be adapted to starting up n copies of <perl script> maybe a little loop that will fire up multiple subshells. Note I'm not a BASH expert

    #!(bash|ksh|sh) <set up environment> for I in {1..n}; do (while true do <perl script> $I # brief delay to ensure everything is shutdown sleep 60 done) &; done

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://977173]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 10:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found