LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-06-2008, 07:25 AM   #1
np1
LQ Newbie
 
Registered: May 2008
Posts: 1

Rep: Reputation: 0
Is there any script to know the cpu load in linux


Hi,

I have written a script in linux that generate loads by creting files. I need to generate load until the CPU load reaches 100%. Please provide the script.

Thanks,
- Nick
 
Old 05-06-2008, 03:48 PM   #2
tidww01
LQ Newbie
 
Registered: Dec 2005
Posts: 19

Rep: Reputation: 0
CPU load alone is not a good indicator of system load. The load value from top is better. However for cpu you could use something like

sar -u 1 1 > tst
tail -1 tst | awk '{print $5}'

This will actually give you the idle cpu percentage. When it reaches 0, your cpu is 100% in use somewhere else.
 
Old 05-07-2008, 01:47 AM   #3
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Worth checking the output of sar -u 1 1 first

On my machine the % idle is the eight entry on the line.

Also, there is no need to put the data into a file:

Code:
sar -u 1 1|tail -1|awk '{print $8}'
 
Old 05-07-2008, 02:03 AM   #4
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
fyi: Not all systems have sar.

you can use top in a script like so:
Code:
top n 1 > some_var
you can grep/awk/sed the output to your liking.

As alternatives, there are iostat and mpstat.

You can always use uptime as well & look for a 1 second load average of 1.00 which may or may not be reliable enough for your purposes.
 
  


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
Teach me about conky and linux resource management... How do I read load? CPU avg? Mysticle31 Linux - Software 1 12-15-2007 06:18 PM
[SOLVED] Dual CPU doesn't load i686/64 bit Linux soplin Linux - Software 3 06-29-2007 06:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:47 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration