6

How can I convert the uptime output to seconds since epoch to compare with dmesg output? Does uptime have the same resolution as the kernel message time? Is there a way to more directly get the kernel time than from uptime?

➜  ~ echo "hi" > /dev/kmsg
➜  ~ dmesg | tail
[  859.214564] hi
➜  ~ uptime
10:08  up 2 days, 43 secs, 2 users, load averages: 1.69 1.64 1.54
1
  • It's still not clear what you're asking. dmesg output isn't seconds since the epoch. What problem are you trying to solve? Are you talking purely about 'time since boot' rather than epoch or kernel time? Feb 24, 2016 at 11:27

2 Answers 2

8

Depending on your flavor of Unix, the /proc filesystem may have an uptime file somewhere with the information you want.

Linux> cat /proc/uptime
5899847.37 23165596.55

And the output of the uptime command for the same time:

Linux> uptime
16:46:27 up 68 days, 6:51,  3 users,  load average: 0.01, 0.02, 0.05

So 5899847.37/86400 = 68.28527 --> 68 days, 6 hours, 51 minutes.

0

kernel time is stored as seconds since Jan 1, 1970. Are you looking to see that as a value? Or are you looking to see what actual date/time the kernel thinks it is?

For the latter, you can just use date -u.

If you want the current seconds since 1st Jan 1970 (epoch), and have perl installed you can run perl -e 'print time()."\n";'

You can also use the date command, using date +"%s" which returns the same information.

If you want to know how long the system has been up, the uptime is the best tool.

2
  • how can i convert the uptime output to seconds since epoch to compare with dmesg output? does uptime have the same resolution as the kernel message time?
    – tarabyte
    Feb 23, 2016 at 18:45
  • Okay that's a completely different question, you might want to update your question to make that clear. Feb 23, 2016 at 18:46

You must log in to answer this question.

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