ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
The minimum timeframe in cron is 1 minute, most cron daemons check every 30 seconds to see if anything needs to be done.
You don't tell what the script does, but isn't it possible to make a loop in the script itseelf (use sleep 1 to pause one second). Loop 59 times. This way you can strat the script every minute (or 5 minutes if you increase the loop.
The link that I had posted in the previous post had the discussion how cron is implemented.
2 concepts were proceeding:
a) Whether cron implemented polling of 30 or 60 seconds.
b) job list is constructed and based on the time the next job in the list to be executed, cron would be signalled accordingly.
When cronentry is edited job list is rebuild again.
(Copied from duplicate thread, to get them all in one...
Other thread was closed by moderator.)
maybe you could use this scritp running in background:
### Sample background worker script
### for linuxquestions.org written
### by Florian Harbich (user doc.nice)
### Free for use or modification, even if
### useless in this variant...
while [ $GOON ]; do
[ -f "$TERMINATORFILE" ] && GOON=0
# do your repeated stuff instead of logger syslog sample here
logger -t BGWorker -- "hi! I'm happy to tell you i'm still alive"
rm -f "$TERMINATORFILE"
you should tell people what you are trying to achieve not how you think
it should be done.
Bigearsbilly is right - I'd listen to him.
And even if you did find some clever, tricky way to get it to work - it's still probably going to be a poor solution to an ill-defined problem...
doc.nice is right, too. If you really want some action repeated every second, your best bet is to create some kind of "daemon" background process or service that loops 1x/second. doc.nice showed you an example in a shell script; you could easily do the same thing in any programming language.
Unless cron can create a new process that then does all its work and shuts down in less than 1 second, the processes will overrun each other.
They'd better be operating on separate and independent bits of data.!
I think the OP should tell us exactly why he'd want to do this.
I suspect that writing your own daemon that pauses for 1 second at the bottom of the processing loop is more appropriate.
If you need it to do its work unit in <1 sec, I'd suggest Perl or C. Shell is not going to be fast enough.
I can maybe see the idea of the script but it doesn't work. %m is the variable for month so not sure what that calculation is actually trying to compute? Using the variable $i in your sleep statement for anything other then 30 seconds doesn't work. i.e. 20 second intervals the sequence would be x x+20 x+40.