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
tarabyte
  • 4,166
  • 10
  • 36
  • 48
  • 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

2 Answers2

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.

Mark Stewart
  • 796
  • 1
  • 7
  • 20
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.

EightBitTony
  • 20,963
  • 4
  • 61
  • 62
  • 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