4

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
  • 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? – EightBitTony Feb 24 '16 at 11:27
6

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.

1

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.

  • 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 '16 at 18:45
  • Okay that's a completely different question, you might want to update your question to make that clear. – EightBitTony Feb 23 '16 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.