Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I run the top command, the third line is;

Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.2%id, 0.1%wa, 0.0%hi, 0.0%si, 0.1%st

From where does top command get this data? Does it get from /proc?, if yes, what is the exact location?

share|improve this question

migrated from stackoverflow.com Apr 24 '13 at 3:06

This question came from our site for professional and enthusiast programmers.

1  
Yes, it usess procfs. –  Roman Newaza Apr 24 '13 at 1:22
add comment

2 Answers

up vote 1 down vote accepted

You are questioning for the exact location of the CPU usage. This is /proc/stat:

$ head -n 3 /proc/stat
cpu  1751981 185577 398478 28868975 69445 32 27028 0 0 0
cpu0 954878 88888 186567 14433502 19750 0 600 0 0 0
cpu1 797103 96688 211911 14435473 49694 31 26428 0 0 0

The format is explained in the Kernel Documentation (filesystems/proc.txt); I bolded the topabbreviations:

The very first "cpu" line aggregates the numbers in all of the other "cpuN" lines. These numbers identify the amount of time the CPU has spent performing different kinds of work. Time units are in USER_HZ (typically hundredths of a second). The meanings of the columns are as follows, from left to right:

  • user: normal processes executing in user mode
  • nice: niced processes executing in user mode
  • system: processes executing in kernel mode
  • idle: twiddling thumbs
  • iowait: waiting for I/O to complete
  • irq: servicing interrupts [hard interrupts hi]
  • softirq: servicing softirqs [soft interrupts si]
  • steal: involuntary wait
  • guest: running a normal guest
  • guest_nice: running a niced guest

General informations about your CPU you can get from /proc/cpuinfo, but this is not related to the CPU usage.

share|improve this answer
add comment

Procfs could be found in /proc. Please read on this: Exploring procfs

Procfs is a virtual file system in linux mounted in /proc, and serves multiple purposes including access to kernel information in userland or for debugging. One of the features which makes Linux special to me is access to process information as a text stream. A lot of linux commands (ps, top, pstree, etc.) rely on this filesystem for information.

You might look through top source code which could be found in coreutils GNU package.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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