Starting never-ending processes without hanging a script
- Dear Perl List,
I have a curious problem. It has to do with how a Perl script can
start a never-ending process without causing the Perl script to
become never-ending itself. Allow me to explain:
I have two scripts. I'll call them the "crontab" and the "tail"
script. The "tail" script basically runs the following command:
------> tail -f /var/log/somelogfile
This command does not exit, it sits there and prints to the screen
every log message that comes in endlessly. I have the Perl "tail"
script setup to send an email if it sees certain lines coming in,
like unauthorized logons and stuff like that.
I created a SEPARATE "crontab" script to monitor that the "tail"
script, to make sure the process is running, and if it is not
running, to fire it back up again. Here is the problem:
When the "crontab" script does not see the "tail" script running, it
fires it up, but in doing so it permanently hangs the "crontab"
script which fired up the "tail" script. This is not a real
solution then because it is not scalable to monitor other log files.
The problem is that you end up with a bunch of the crontab scripts
sleeping waiting for the tail script to finish, which it never will.
I asked a sysadmin for a way to start processes that behave like
daemons, but he didn't have an answer. He started to point me in
the direction of signals, like a HUP signal or something, but I don't
know how to send a signal to start a script or program. Is there a
solution within Perl to graciously and elegantly handle this problem??
Thanks in advace for any pointers/suggestions,