Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
So I have a naughty perl script which runs via cron every 10 minutes. After a few days of uptime on server, for some reason the process doesnt seem to die and the perl process eats all my CPU and doesnt close.
I am wondering if there is a parm you can pass to the perl program which limits execution to say 30 seconds and then automatically kills the process? If not through perl, how about through cron tab, again limit to 30 seconds and after that time automatically kill the perl process.
You could create another script and tell it to run every 10 mins (like your perl script) and then have it wait 30 secs - check to see if the perl script is running (vi ps or something) and then kill it if it is still running.
So how would this script look? Currently perl is being naughty and has stuck open. How do I check if the process is running? Do I just check for perl? How do I know I am not killing other perl processes that are running, but are not the naughty processes?
I suppose I could run it under a custom username (perlCron) in cron, then I check for perl running under user (perlCron), if it is running then kill PID.
Could you write a script which does what I explained above? I not good at scripting.
Thanks.
Last edited by JustinK101; 11-08-2007 at 06:56 PM.
Say your cronjob spawns a process with the commandline "/usr/sbin/larch.pl /etc/trees.conf", then you could add a cronjob like this:
Code:
#!/bin/sh
# Sleep for 30 seconds.
sleep 30s
# Find process by commandline and -KILL it.
pkill -9 -f "/usr/sbin/larch.pl /etc/trees.conf"
# Exit the shellscript the right way.
exit 0
It should be scheduled to run at the same interval as your other cronjob.
Thank you very much, I tweaked your scipt a little bit since when I first tried it, it did not kill the processes. Basically I run the perl process under its own username in the crontab, perlCron. So the script now looks like:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.