8

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?

1
  • 1
    Yes, it usess procfs. Apr 24, 2013 at 1:22

2 Answers 2

5

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.

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .