blackdog said:
I have a perl script, I like to kill it (commit suicide) if the script
is running on the system for more than one hour. What is the best way
to do it?
Are you saying you want the program to automatically exit if it's been
running for an hour? At the start of your program, get the current
time (see: perldoc -f time). Periodically in your code, presumably in
a main central loop of some kind, check the current time. If the two
times are more than 3600 seconds apart, exit (see: perldoc -f exit).
You may also wish to make use of the END { } block (see: perldoc
perlmod) for any cleanup code that you wish to happen.
If, on the other hand, you want some external process to periodically
check your Perl program to see if it's been running for an hour, then
your question is off topic for this group, as the question does not at
all depend on the language in which the hour-long script was written.
If, on a mysterious third hand, you want this external process which
periodically checks your Perl script to also be written in Perl, then
your question is back on topic here. You may wish to use the CPAN
module Proc:
rocessTable to determine how long your program has been
running for, and then send it a signal (see: perldoc -f kill). Your
hour-long script would have to handle that signal, of course. (see:
perldoc perlipc and perldoc perlvar (searching for %SIG)).
Once you've made your attempt to solve your problem, if you cannot get
satisfactory results, feel free to post what you've tried here. Be
sure to read and follow the Posting Guidelines for this group, which
are posted here twice a week, to maximize your chances of getting good
help.
Paul Lalli