LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How Top command works (https://www.linuxquestions.org/questions/linux-general-1/how-top-command-works-630962/)

gsivaprakashreddy 03-27-2008 04:39 AM

How Top command works
 
Hi!

I am trying to send an trap when cpu idle becomes 0% or below 90%. I am reading cat /proc/stat file for cpu idle value, but every time cpu idle is showing above 90% at the same time when i execute top command here cpu idle is showing below 90% sometimes it showing 0% also.

How top command works and from where top command getting cpu utilization information and how it is getting updated for every few seconds.

tell me, from where i'll get latest cpu idle value for every few seconds.

Please help me out.

With Regards,
G. Siva Prakash Reddy.

bigrigdriver 03-27-2008 08:04 PM

Read the fine manual: man top.

sundialsvcs 03-27-2008 11:09 PM

In a Linux system, top gets its information from a very interesting source ... "the /proc file system"

If you look at the root-directory of your system, you'll probably notice two directories ... /proc and /sys ... which upon closer inspection show themselves to be most curious. Although at first glance they appear to contain "files and directories," you soon realize that these are not "ordinary, physical files." And indeed, they are not.

The "files and directories" in these "directories" are, in fact, pure fabrications created for you by Linux itself. All kinds of information, including everything needed by a command like top, can be obtained by finding and reading these "files." When you "read from" (and sometimes, "write to") these "files and directories," the information comes from the bowels of the system itself. And you'd never know it!

So, top in Linux is not a "privileged" program at all.

It's quite a remarkable and useful concept, extremely well-implemented and very characteristic of Linux.

gsivaprakashreddy 03-27-2008 11:13 PM

How Top Comand Works
 
Hi!
I know man top will give the information.
My question is how top command getting information and displaying it, what and all files it is refering and fetching the content.
I want cpu utilization information.I saw /proc/stat file,but comparing the values from this file and top command both will have different values.

Please help me out.

With Regards,
G. Siva Prakash Reddy.

gsivaprakashreddy 03-28-2008 12:59 AM

How top command works
 
Hi,
Thanks for the response.
but can i get a clear data regarding CPU Idle information.
i find that top command gives :

top - 11:16:56 up 65 days, 18:17, 13 users, load average: 0.03, 0.37, 0.29
Tasks: 108 total, 2 running, 106 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.7%us, 0.0%sy, 0.0%ni, 99.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1027096k total, 980428k used, 46668k free, 384136k buffers
Swap: 1614492k total, 29776k used, 1584716k free, 194120k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND


Please advice me how the high lighted info (in Red colour) is being calculated or which file should i refer to get the exact CPU Idle time for every X seconds.

Regards,
Siva

syg00 03-28-2008 01:15 AM

It's not in any file (that I'm aware of anyway) - you have to calculate the delta each time you probe /proc/stat. Being aware (of course) of the number of timer ticks that have occurred in that period.

gsivaprakashreddy 03-28-2008 02:17 AM

Hi!syg00

Which value i should consider, but when i open file the file looks like as shown below:
cpu 14055380 1035640 1439077 546907255 5237533 28025 63972 0
cpu0 14055380 1035640 1439077 546907255 5237533 28025 63972 0
intr 1516285645 1421813115 1315 0 2 1 0 0 0 0 1 0 0 4871 0 20360162 10704019 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 63402159 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ctxt 242926257
btime 1201021159
processes 7863707
procs_running 1
procs_blocked 0

if you know how to calculate cpu idle , please do let me know.

with Regards,
G. Siva Prakash Reddy.

Tinkster 03-28-2008 05:33 PM

http://www.linuxquestions.org/questi...-usage-629813/



Cheers,
Tink


All times are GMT -5. The time now is 10:34 PM.