5

This question already has an answer here:

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 *

marked as duplicate by slm, jasonwryan, jordanm, Anthon, Zelda Jan 22 '14 at 7:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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? – Patrick Jan 22 '14 at 4:33
  • uptime: 21:24 ..cat \proc\uptime: 77098.74 103113.16. They are slightly different though.. – Atieh Jan 22 '14 at 7:40
6

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.

If you have a copy of the kernel source around, check out fs/proc/uptime.c 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.

  • 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

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