|
|
Run a cron process more than every minute
Any solution that just sleeps 15 and then does something, repeatedly, will drift away from once every 15 seconds, due to the non-zero time it takes to do something. And that can vary depending on the load on your computer.
To stay in cadence, you can just sleep however long it takes until the time is evenly divisible by 15 seconds. This takes the limited but non-zero arithmetic available to the bash shell.
Run a cron process more than every minute
You rock.
Run a cron process more than every minute
Something like this is the way to go if only shell tools are to be used, but this solution has problems. If the open is fast enough, the time in seconds might be the same multiple of dt that it was before. Then sleep 0 will be executed and the open will be executed too soon. A quick fix would be to test for 0 sleep times and change them to dt. Better would be to monitor the execution starts explicitly. Get the time at the beginning, say "start" and at iteration i sleep until time start+dt*i where the first iteration is i=1.
Run a cron process more than every minute
The expression "${dt} - \( ${now} % ${dt} \)" always gives a value from 1 to 15 (for dt = 15). The '%' operator takes the remainder when now is divided by 15, which is always in the range 0-14 , and 15 minus that puts it in the 15-1 range, respectively. |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.52 seconds |
|