How to print kernel time from command line

dmesguptime

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

Best Answer

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.