8

I have used both uptime and cat /proc/uptime commands. I know the idle time in the later can be greater than running time (multiprocessors). However, when I add both running and idle times, and compare it to the uptime (5:30 hrs) they are not equal. I assume it's because the uptime returns the real time and the cat /proc/uptime returns processor(s) time.

Short things clear, I want to know the reason exactly and I want to know which one to choose, according to the topic.

Also, is it possible to get the processor(s) time in the last 24 hours?

NOTE: Please read this article to understand where this is going.

*Distributor ID: Ubuntu Description: Ubuntu 12.04.2 LTS Release: 12.04 Codename: precise *

Zelda
  • 6,158
  • 1
  • 21
  • 27
Atieh
  • 223
  • 1
  • 3
  • 8
  • The first field of `/proc/uptime` is the uptime in wall time. Meaning it's real time, not CPU time. If that doesn't match the value of `uptime`, then you've got some voodoo going on. Can you provide the output of each for us to look at? – phemmer Jan 22 '14 at 04:33
  • `uptime`: 21:24 ..`cat \proc\uptime`: 77098.74 103113.16. They are slightly different though.. – Atieh Jan 22 '14 at 07:40

1 Answers1

9

The uptime command reads the two values out of /proc/uptime, actually. The first value is the amount of time since the machine booted. The second value, however, is the sum of time that each cpu has not had a runnable process to schedule.

Check out fs/proc/uptime.c from the Linux kernel github and you'll see how the /proc/uptime file's content is generated.

So, to clearly answer, the amount of seconds+milliseconds since the computer booted is the first value in the output of cat /proc/uptime.

iFreilicht
  • 898
  • 10
  • 14
etherfish
  • 1,264
  • 6
  • 10
  • For example, a largely idle server I have access to has a /proc/uptime contents of "9843159.39 117450954.76". It has 12 CPUs. You'll notice that the second value divided by the first, equals 11.9322 which means I've had a little shy of 12 processors totally idle for the past 2,700 hours. – etherfish Jan 21 '14 at 17:33
  • No offense, but can you rephrase what you said? How could this answer my question? – Atieh Jan 21 '14 at 20:46
  • So the first value is equal to the 5:30 hrs..? So uptime command excludes the idle time when it gives me time in the format of 5:30? – Atieh Jan 21 '14 at 20:49