Hy people, I have to run a cronjob every 15 seconds, and i have a doubt, does runing a job so quickly overload the machine??, i dont mean if the job that cron runs loads the machine, i mean does cron load the machine by itself each time it runs to look for jobs?? is it a good idea??? THnx
On Thursday 23 February 2006 18:33, daniel parkes wrote:
Hy people,
I have to run a cronjob every 15 seconds, and i have a doubt, does runing a job so quickly overload the machine??, i dont mean if the job that cron runs loads the machine, i mean does cron load the machine by itself each time it runs to look for jobs??
You can do it. The load depends on your job. cron does not load the machine by any significant amount. Take care that your job finishes in less than 15 seconds, or you'll have more than one in parallel.
daniel parkes wrote:
Hy people,
I have to run a cronjob every 15 seconds, and i have a doubt, does runing a job so quickly overload the machine??, i dont mean if the job that cron runs loads the machine, i mean does cron load the machine by itself each time it runs to look for jobs??
is it a good idea???
A more relevant question would be "is it possible", to which the answer would be "no". cron can only handle minutes, not seconds, so the best you can do through cron is once per minute. If you have to run something every 15 seconds, I think you're looking in the wrong place. If you can explain more what exactly you are trying to do, then perhaps someone can give you a better way of accomplishing it
On Thursday 23 February 2006 11:33 am, daniel parkes wrote:
I have to run a cronjob every 15 seconds, and i have a doubt, does runing a job so quickly overload the machine??, i dont mean if the job that cron runs loads the machine, i mean does cron load the machine by itself each time it runs to look for jobs?? Cron runs on a 1 minute interval, but it stays in memory as it is a daemon. If you need to run a task every 15 seconds you should simply run it as a daemon. It is trivial to wrap something in a script: #!/bin/bash while [ 1 ] do # do whatever task you want to do sleep 15 # sleep for 15 seconds done -- Jerry Feldman
Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
Jerry Feldman wrote:
#!/bin/bash while [ 1 ] do # do whatever task you want to do sleep 15 # sleep for 15 seconds done
I know you know this Jerry, but I still have to point this out: this won't run every 15 seconds, it will run at 15 second intervals. To get something run every 15 seconds, you have to do something like a C program with a timer giving a SIGALRM every 15 seconds, and set whatever it is you want to do as a signal handler. And if the 15 second thing is a strict requirement, you also have to run it as a realtime process
Anders Johansson wrote:
I know you know this Jerry, but I still have to point this out: this won't run every 15 seconds, it will run at 15 second intervals.
Silly me. Of course the "whatever task" could be launched in the background, which would bring it closer to "every 15 seconds", which might be good enough
On Thursday 23 February 2006 13:17, Anders Johansson wrote:
Anders Johansson wrote:
I know you know this Jerry, but I still have to point this out: this won't run every 15 seconds, it will run at 15 second intervals.
Silly me. Of course the "whatever task" could be launched in the background, which would bring it closer to "every 15 seconds", which might be good enough
But perhaps the way Jerry wrote it would be best.... Since it would allow the program to finish each time. Or... if it is observed that the program takes 3 seconds to run (as an average) then the sleep time could be reduced to 12 secs. and thus if the job took 5 secs. on occasion, no harm would be done. At least that's the way I would do it (not knowing what the OP wants to accomplish)
On Thursday 23 February 2006 2:41 pm, Bruce Marshall wrote:
On Thursday 23 February 2006 13:17, Anders Johansson wrote:
Anders Johansson wrote:
I know you know this Jerry, but I still have to point this out: this won't run every 15 seconds, it will run at 15 second intervals.
Silly me. Of course the "whatever task" could be launched in the background, which would bring it closer to "every 15 seconds", which might be good enough
But perhaps the way Jerry wrote it would be best.... Since it would allow the program to finish each time.
Or... if it is observed that the program takes 3 seconds to run (as an average) then the sleep time could be reduced to 12 secs. and thus if the job took 5 secs. on occasion, no harm would be done.
At least that's the way I would do it (not knowing what the OP wants to accomplish) In the scriptlet that I posted, the task itself could be spun off asynchronously: #!/bin/bash while [ 1 ] do jobyouwanttorun& #Run this asynchronously sleep 15 # sleep for 15 seconds done What this will do is to start your task once every 15 seconds regardless of how long the task takes to run. -- Jerry Feldman
Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
Ok i understad,
and running this script is a good idea?
#!/bin/bash
while [ 1 ]
do
jobyouwanttorun& #Run this asynchronously
sleep 15 # sleep for 15 seconds
done
the thing is that i have a oracle rac that run a job every 5 seconds,
but because of a bug in oracle the jobs have a memory leak, so we
tried with control-m but it can only run every 2 minutes wich is not
enough, thats why we were thinking of runing the jon in the crontab,
but i didnt know it has a 1 minute interval.
the job can take from less than 1 second to finish to 45 seconds.
Thnx all
On 23/02/06, Jerry Feldman
On Thursday 23 February 2006 2:41 pm, Bruce Marshall wrote:
On Thursday 23 February 2006 13:17, Anders Johansson wrote:
Anders Johansson wrote:
I know you know this Jerry, but I still have to point this out: this won't run every 15 seconds, it will run at 15 second intervals.
Silly me. Of course the "whatever task" could be launched in the background, which would bring it closer to "every 15 seconds", which might be good enough
But perhaps the way Jerry wrote it would be best.... Since it would allow the program to finish each time.
Or... if it is observed that the program takes 3 seconds to run (as an average) then the sleep time could be reduced to 12 secs. and thus if the job took 5 secs. on occasion, no harm would be done.
At least that's the way I would do it (not knowing what the OP wants to accomplish) In the scriptlet that I posted, the task itself could be spun off asynchronously: #!/bin/bash while [ 1 ] do jobyouwanttorun& #Run this asynchronously sleep 15 # sleep for 15 seconds done What this will do is to start your task once every 15 seconds regardless of how long the task takes to run. -- Jerry Feldman
Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9 -- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
Bruce Marshall wrote:
On Thursday 23 February 2006 13:17, Anders Johansson wrote:
Anders Johansson wrote:
I know you know this Jerry, but I still have to point this out: this won't run every 15 seconds, it will run at 15 second intervals.
Silly me. Of course the "whatever task" could be launched in the background, which would bring it closer to "every 15 seconds", which might be good enough
But perhaps the way Jerry wrote it would be best.... Since it would allow the program to finish each time.
Or... if it is observed that the program takes 3 seconds to run (as an average) then the sleep time could be reduced to 12 secs. and thus if the job took 5 secs. on occasion, no harm would be done.
At least that's the way I would do it (not knowing what the OP wants to accomplish)
While all my code-writing experience lies outside of *nix, if the OP can tolerate a small amount of drift, and the task runs in under 15sec, perhaps the script Jerry suggested could simply execute the task 4 times, at 15sec intervals, and the script would be called onver per minute by cron. That way (assuming certain of my assumptions are correct), there would be a possibility for some drift between the repetitions within a given minute, but cron should 're-sync' the task at the top of every minute. If the task runs close to 15sec, there's a possibility of overlap at the top of each minute, when cron calls the script again. But if this is tolerable, it might work for the OP's purposes.
On Thu, 2006-02-23 at 17:33 +0100, daniel parkes wrote:
Hy people,
I have to run a cronjob every 15 seconds, and i have a doubt, does runing a job so quickly overload the machine??, i dont mean if the job that cron runs loads the machine, i mean does cron load the machine by itself each time it runs to look for jobs??
is it a good idea???
I never knew you could run a cron job any more frequently than once a minute. Perhaps the program is respawning itself more often? -- Ken Schneider UNIX since 1989, linux since 1994, SuSE since 1998
participants (7)
-
Anders Johansson
-
Bruce Marshall
-
daniel parkes
-
David McMillan
-
Jerry Feldman
-
Ken Schneider
-
Silviu Marin-Caea