Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there an easy way to determine the time in ticks, using date between now and some time tomorrow.

share|improve this question
I need this to feed to the RTC and wake up the computer from hibernate mode. – Vek.M1234 Feb 1 '14 at 16:14
How long is a tick? – Benjamin Barenblat Feb 1 '14 at 16:59
@BenjaminBarenblat - That entirely depends on time system the operating system is using. – Ramhound Feb 1 '14 at 17:33
Relevant: Converting jiffies to milli seconds – terdon Feb 1 '14 at 19:22
I thought the time in seconds was enough for an RTC wake? Are you sure you need it in ticks? – Jan Fabry Feb 1 '14 at 20:53
up vote 2 down vote accepted

Off the top of my head - I'd look at the UNIX def of "Epoch Time", figure out the begin and end epoch times of interest, subtract, and then scale that to whatever.

Now, about your specific question about using the DATE(1) command, the UNIX man page for DATE(1) in the BSD General Commands Manual has this example:

Finally the command:

date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"

can be used to parse the output from date and express it in Epoch time.

On my OSX system, I get:

[3] date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"

The date -r seconds command will probably prove useful for sanity checks with the epoch time values you compute:

[5] date -r 1391275286
Sat Feb  1 09:21:26 PST 2014

Here is another approach that may work for you...

Another possibile implementation to accomplish what you are trying to do would be with the UNIX at command, assuming these kind of background jobs are run while your flavor of xNIX is "asleep". On my OSX system it appears that commands specified with the at command are executed even while OSX is "asleep" - I do have "power nap" enabled, if that has anything to do with it, but offered for you consideration:

First, on OSX, the at command is disabled by default, so I first enabled it as per the the ATRUN(8) man page as follows:

Execute the following command as root to enable at run:

    launchctl load -w /System/Library/LaunchDaemons/

Then, I did a sleep test as follows:

[61] date
Sat Feb  1 11:10:17 PST 2014
[62] at 11:11am today
touch $HOME/created-at-11:11am
job 9 at Sat Feb  1 11:11:00 2014
[63] date
Sat Feb  1 11:10:40 PST 2014

at this point, I put my OSX laptop to sleep, went in the kitchen and made a salad, came back, and here's the results:

[64] echo "awakened now"; date
awakened now
Sat Feb  1 11:15:59 PST 2014
[65] ls -l ~/created-at-11\:11am
-rw-r--r--+ 1 whmcclos staff 0 Feb  1 11:11 /Users/whmcclos/created-at-11:11am

So, it may be possible that the implementation of your particular at command will allow what you are trying to do.

share|improve this answer

You have to be really careful when using kernel time structures (ticks and jiffies were meant to be used only by the scheduler for multitasking and internal kernel processes) .

Linux uses jiffies, not ticks (Windows, Unix and the BSDs use ticks), and the amount of time varies per the architecture. On an x86 or AMD64 platform, Linux has 100 Jiffies per second (by default, this can be changed). Also, there's no guarantee that a Jiffy is exactly 10ms, various factors can change it by a little bit each time, and eventually this can add up to a meaningful difference.

Getting more complicated, the latest kernels are tickless, their kernels do not "wake up" on a regular interval to do multitasking and all that. Instead each time a "wake up" is done, the kernel figures out when it needs to wake up next and schedules an interrupt timer to fire at that time. On these systems there's no such thing as a tick or jiffy with a consistent time allocation.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .