Linux - Software This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
03-26-2009, 06:49 PM
|
#1
|
LQ Newbie
Registered: Dec 2007
Location: Greensboro, NC
Distribution: Fedora
Posts: 8
Rep:
|
Faster than Crontab
Is there anything faster than crontab? I am working on a project and need crontab to run faster than it currently does. Is that possible or is there software I can install to get it to do that?
|
|
|
03-26-2009, 07:44 PM
|
#2
|
Member
Registered: Nov 2007
Location: /home/watcher69b
Distribution: RH, Fedora & CentOS
Posts: 552
Rep:
|
what do you mean 'faster'?
|
|
|
03-27-2009, 09:28 AM
|
#3
|
LQ Newbie
Registered: Dec 2007
Location: Greensboro, NC
Distribution: Fedora
Posts: 8
Original Poster
Rep:
|
I need something that will run more often than a minute.
|
|
|
03-28-2009, 01:20 AM
|
#4
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,430
|
My rule of thumb is that its a waste of resources to ask cron to keep initialising new processes more than every 5 mins. There's quite an overhead, it has to create a whole new proc env every time.
Use a daemon containing infinite loop and wait as long or short as reqd at the bottom of the loop.
|
|
|
03-28-2009, 02:13 AM
|
#5
|
LQ Newbie
Registered: Dec 2007
Location: Greensboro, NC
Distribution: Fedora
Posts: 8
Original Poster
Rep:
|
Quote:
Originally Posted by chrism01
My rule of thumb is that its a waste of resources to ask cron to keep initialising new processes more than every 5 mins. There's quite an overhead, it has to create a whole new proc env every time.
Use a daemon containing infinite loop and wait as long or short as reqd at the bottom of the loop.
|
Can you give me an example of that?
|
|
|
03-28-2009, 07:54 AM
|
#6
|
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196
|
Code:
#!/bin/bash
while [ 1 ]
do
/path/to/your/program
sleep 20
done
jlinkels
|
|
|
03-28-2009, 09:17 AM
|
#7
|
LQ Newbie
Registered: Dec 2007
Location: Greensboro, NC
Distribution: Fedora
Posts: 8
Original Poster
Rep:
|
Quote:
Originally Posted by jlinkels
Code:
#!/bin/bash
while [ 1 ]
do
/path/to/your/program
sleep 20
done
jlinkels
|
So does that sleep it from 20 seconds or 20 minutes? I'm assuming seconds.
|
|
|
03-28-2009, 12:13 PM
|
#8
|
LQ 5k Club
Registered: May 2003
Location: London, UK
Distribution: Fedora40
Posts: 6,153
|
From man sleep:
Code:
SYNOPSIS
sleep NUMBER[SUFFIX]...
sleep OPTION
DESCRIPTION
Pause for NUMBER seconds. SUFFIX may be ‘s’ for seconds (the default), ‘m’ for minutes, ‘h’ for hours or ‘d’ for
days. Unlike most implementations that require NUMBER be an integer, here NUMBER may be an arbitrary floating point
number. Given two or more arguments, pause for the amount of time specified by the sum of their values.
|
|
|
03-28-2009, 12:20 PM
|
#9
|
LQ Newbie
Registered: Dec 2007
Location: Greensboro, NC
Distribution: Fedora
Posts: 8
Original Poster
Rep:
|
Quote:
Originally Posted by tredegar
From man sleep:
Code:
SYNOPSIS
sleep NUMBER[SUFFIX]...
sleep OPTION
DESCRIPTION
Pause for NUMBER seconds. SUFFIX may be ‘s’ for seconds (the default), ‘m’ for minutes, ‘h’ for hours or ‘d’ for
days. Unlike most implementations that require NUMBER be an integer, here NUMBER may be an arbitrary floating point
number. Given two or more arguments, pause for the amount of time specified by the sum of their values.
|
Cool...cool...Thanks
|
|
|
03-28-2009, 12:46 PM
|
#10
|
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196
|
Quote:
Originally Posted by majorlinux
So does that sleep it from 20 seconds or 20 minutes?
|
20 hours.
If you are too lazy to read the manual page or to check the TLDP website I am sorry to have put in my time to help you.
jlinkels
|
|
|
03-28-2009, 12:48 PM
|
#11
|
LQ Newbie
Registered: Dec 2007
Location: Greensboro, NC
Distribution: Fedora
Posts: 8
Original Poster
Rep:
|
Quote:
Originally Posted by jlinkels
20 hours.
If you are too lazy to read the manual page or to check the TLDP website I am sorry to have put in my time to help you.
jlinkels
|
I mean, I only asked because I'm not at the server right now. So many angry people...
|
|
|
03-28-2009, 01:04 PM
|
#12
|
LQ 5k Club
Registered: May 2003
Location: London, UK
Distribution: Fedora40
Posts: 6,153
|
Please calm down.
It's worth remembering that the interweb knows almost everything there is to know about, including man pages. Eg here:
http://linux.die.net/man/
They come nicely formatted too 
|
|
|
03-28-2009, 01:32 PM
|
#13
|
Member
Registered: Oct 2008
Location: Norway
Distribution: Slackware
Posts: 77
Rep:
|
Quote:
Originally Posted by jlinkels
Code:
#!/bin/bash
while [ 1 ]
do
/path/to/your/program
sleep 20
done
|
Nice, but what if you want this, like the subject says, to be like cron? I mean, what if you want the program to be run at 00:00:00, then at 00:00:20, then at 00:00:40, then at 00:01:00, then at 00:01:20, and so on.
Now, add the fact that 'program' runs between 1 and 10 seconds so a simple 'sleep' would not do the trick. You would like a 'sleep 20 sec measured from the previous sleep including running time of the program'.
'program' can look like this:
Code:
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
int main (void)
{
srandom(time(NULL));
sleep((int)(10*(double)rand()/RAND_MAX));
return 0;
}
Guess you can use 'time' and measure the time spent in 'program', and then figure out how long the sleep will be.
-Bob-
|
|
|
03-28-2009, 03:47 PM
|
#14
|
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196
|
Look at this post of mine:
http://www.linuxquestions.org/questi...-timer-714154/
But there is a syntax error in my code, it was corrected in the succeeding post.
jlinkels
|
|
|
All times are GMT -5. The time now is 03:20 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|