LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Is there any script to know the cpu load in linux (https://www.linuxquestions.org/questions/linux-software-2/is-there-any-script-to-know-the-cpu-load-in-linux-640262/)

np1 05-06-2008 07:25 AM

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

tidww01 05-06-2008 03:48 PM

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.

Disillusionist 05-07-2008 01:47 AM

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}'

BrianK 05-07-2008 02:03 AM

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.


All times are GMT -5. The time now is 05:19 PM.