Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


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

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


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.

- Nick
Old 05-06-2008, 04:48 PM   #2
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, 02:47 AM   #3
Senior Member
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 97
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:

sar -u 1 1|tail -1|awk '{print $8}'
Old 05-07-2008, 03:03 AM   #4
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:
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.


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 07:18 PM
[SOLVED] Dual CPU doesn't load i686/64 bit Linux soplin Linux - Software 3 06-29-2007 07:24 PM > Forums > Linux Forums > Linux - Software

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

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