Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Process Reliablity

by atl (Pilgrim)
on Jul 20, 2000 at 15:58 UTC ( [id://23353]=note: print w/replies, xml ) Need Help??


in reply to Process Reliablity

Nice, elegant suggestions, and I would recommend using the pid file approach. There is a trick how you can make this file disappear even if the process crashes (some inode trickery, but I cannot give an example right now).

If you need a quick hack, I can offer you two low level solutions (sort of). Assuming you are using some sort of unix, you might want to try this:

1. Use a wrapper script to start your program. It can restart it whenever the program crashed:

#!/bin/sh while true do start_your_program sleep xxx done
Advantage: the auto restart releaves you of checking all the time.
Beware, though, that this might mean trouble if your program does ugly things when restarted after a crash and might put considerable load on your machine in a continous start-crash-restart cycle if you omit a proper sleep time.

2. You might grep through the process list to see if you program is running. This works if it has a sufficiently long and distinct name. Try on a shell:

ps aux | grep your_program_name | grep -v grep | wc -l
or
ps -ef | grep your_program_name | grep -v grep | wc -l
depending on which unix flavour you use.
This returns the number of instances of your program running (i.e. usually 0 or 1). YOu can use that from a perl script, too, putting the expression into backticks (``).

Hope that's a bit useful. Kind of old techniques, but it still works (most of the time) ;-)

Andreas

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-28 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found