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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.