Perl:Suicide if take long
Hi..
Do you have any idea how I may kill my own Perl script if it is running for more than threshold minutes? Thanks. |
Does the system you're using have the at command? If so, have your Perl script execute an appropriate "at" command immediately after the script starts. You use "at" to launch a another script that kills the original Perl script if it's still running after X minutes/hours/days.
|
Dear Dark_Helmet,
I use cronetab to run my script every minute, therefore I want to be sure that it is closed after for example 30 second so that at each minutes just one instance of the script is running.. Thanks for your attention. |
How about a bash wrapper script?
Code:
#!/bin/bash |
Wise and nice script, for sure it may help, but do you have any idea how to do it within shell script that makes the script be killed independent of OS it is running on?
Thanks.. |
Sorry -- I don't perl
EDIT: But surely perl can do it -- it's a powerful language. In case it helps, I'd do it like this in bash Code:
#!/bin/bash |
Why shouldn't the Perl script in question just kill itself ?
For that you can use threads. I.e. use threads (or forks; threads work on any system), create a thread which just waits for the given timeout to expire, and when it expires, it calls built-in Perl 'kill' function (see perldoc -f kill) with PID of the script (the $$ variable). The other thread will be the script proper itself, i.e. it will do the useful job. Read about threads here: http://perldoc.perl.org/threads.html . And about forks: http://search.cpan.org/~rybskej/forks-0.34/lib/forks.pm . If you want cross-platform, as I said, you need threads and not forks. |
All times are GMT -5. The time now is 02:42 PM. |