LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-11-2009, 08:05 PM   #1
dangdtvn
LQ Newbie
 
Registered: Aug 2008
Location: Viet Nam
Distribution: OpenSource - RedHat
Posts: 10

Rep: Reputation: 0
Question How to get usage of CPU, Memory ?


Dear all,

i am wondering How to get usage of CPU, Memory in linux environment? So would you able to tell me the ways?


thanks.
 
Old 01-11-2009, 08:09 PM   #2
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 227Reputation: 227Reputation: 227
man top
 
Old 01-11-2009, 09:36 PM   #3
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 41
man getrusage
 
Old 01-12-2009, 06:08 PM   #4
rob33n
Member
 
Registered: May 2007
Location: Turkey
Distribution: Ubuntu - Debian
Posts: 134

Rep: Reputation: 16
When I typed this code I got an error like:
Quote:
man getrusage
No manual entry for getrusage
 
Old 01-12-2009, 06:29 PM   #5
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 809

Rep: Reputation: 178Reputation: 178
Quote:
No manual entry for getrusage
Then go here.
 
Old 01-12-2009, 06:51 PM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
One can find various Linux man pages on www.die.net .
 
Old 01-13-2009, 02:34 AM   #7
dangdtvn
LQ Newbie
 
Registered: Aug 2008
Location: Viet Nam
Distribution: OpenSource - RedHat
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bgeddy View Post
man top
i am not only want to view this result of top command but also i want to take this information to edit. somebody think that all the information that return by top command will be saved to a file at somewhere in linux and it will be refreshed after a period of time.
 
Old 01-13-2009, 02:39 AM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,352

Rep: Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042
The manpage has info on how run top in batch - you can write the output to a file, and put it in a timed loop if you want.
A better option is something like sar to maintain historical data - it is part of the sysstat package.
 
Old 01-13-2009, 08:17 PM   #9
dangdtvn
LQ Newbie
 
Registered: Aug 2008
Location: Viet Nam
Distribution: OpenSource - RedHat
Posts: 10

Original Poster
Rep: Reputation: 0
Cool

Quote:
Originally Posted by syg00 View Post
The manpage has info on how run top in batch - you can write the output to a file, and put it in a timed loop if you want.
A better option is something like sar to maintain historical data - it is part of the sysstat package.
i found that the CPU usage are stored in /proc/stat. when i execute this command: cat /proc/stat, it returns the following result:

> cat /proc/stat
cpu 2255 34 2290 22625563 6290 127 456
cpu0 1132 34 1441 11311718 3675 127 438
cpu1 1123 0 849 11313845 2614 0 18
intr 114930548 113199788 3 0 5 263 0 4 [... lots more numbers ...]
ctxt 1990473
btime 1062191376
processes 2915
procs_running 1
procs_blocked 0


somebody can tell me the detail what cpu,cpu0,cpu1 is?
 
Old 01-13-2009, 08:31 PM   #10
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,352

Rep: Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042
These data are not "stored" in /proc/stat, they are merely presented to you via /proc/stat - the proc filesystem is not real, but a pseudo f/s that is a means of exposing kernel data to userspace (i.e. you). The numbers are cummulative, and valid only at the instant in time that you read the /proc/stat. Plenty of discussions here at LQ, and on the wider 'net

All the /proc "files" are detailed in "man proc".
In this case, these numbers are used to produce the (more readable) fields in the header of the "top" command.
 
Old 01-13-2009, 08:49 PM   #11
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
Quote:
Originally Posted by dangdtvn View Post
somebody can tell me the detail what cpu,cpu0,cpu1 is?
So,you have two processors,cpu0 is the first and cpu1 is the second.Cpu is cpu0 + cpu1.To see some info about your processors you can use mpstat command.If you want to use sar then you can use it as sar -u 5 5 it will display 5 lines after every 5 seconds regarding cpu,of course.To understand the output,here's something;
Quote:
* %user: Percentage of CPU utilization that occurred while executing at the user level (application).
* %nice: Percentage of CPU utilization that occurred while executing at the user level with nice priority.
* %system: Percentage of CPU utilization that occurred while executing at the system level (kernel).
* %iowait: Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
* %idle: Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
.
If you want to have a file where this reports are saved use;
Code:
# nohup sar -o output.file 12 8 >/dev/null 2>&1 &
where you need to set path for the file.To see which processes are using cpu the most run;
Code:
# ps -eo pcpu,pid,user,args | sort -r -k1 | less
.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cpu and memory usage graziano1968 Linux - General 1 04-21-2007 06:49 AM
getting realtime info on memory usage-cpu and harddrive usage steering Linux - Newbie 5 03-03-2005 08:43 PM
CPU and memory usage suguname Linux - Newbie 3 02-01-2005 01:45 PM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
Controlling CPU usage & memory usage Saravana babu Linux - Software 0 02-18-2004 05:55 AM


All times are GMT -5. The time now is 10:38 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration