Visit Jeremy's Blog.
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 04-24-2010, 05:15 PM   #1
ninja master
Registered: May 2008
Distribution: funtoo/gentoo amd64 xwrt
Posts: 412

Rep: Reputation: 31
command line cpu utilization

how would one take the mpstat command, and have the idle time subtracted from 100.... then dump said number to a file or preferably print it to command line?

i want my cpu utilization in non robot time and in non robot /proc/loadavg

thats right i want total cpu utilization % printed in bash (why doesnt nix have this in the proc folder?) (why doesnt mp stat have a flag to show total cpu usage and not give me the run around with % kernel is using % user is using % sys % nice??????)

i asked in another thread but they told me to forward x on an xless system. i can see several ways to display cpu utilization but none answering the question and google totally gives the same answer they gave in the other thread.

sar is broken on this machine, and it is non existent on the other.

sar is now broken on the linux from scratch machine also, and mpstat is running strong on it also =)

with this question, i would like to add for SMP users such as myself.... how would one do that same % but instead of system total, %'s run on individual cores.

much thanks LQ, and im one of the top folders on the folding@home team now =)
Old 04-24-2010, 05:41 PM   #2
ninja master
Registered: May 2008
Distribution: funtoo/gentoo amd64 xwrt
Posts: 412

Original Poster
Rep: Reputation: 31
# by Paul Colby (, no rights reserved ;)
# modified by a drunken penguin to take a simple snapshot of cpu usage


while true; do
  CPU=(`cat /proc/stat | grep '^cpu '`) # Get the total CPU statistics.
  unset CPU[0]                          # Discard the "cpu" prefix.
  IDLE=${CPU[4]}                        # Get the idle CPU time.

  # Calculate the total CPU time.
  for VALUE in "${CPU[@]}"; do

  # Calculate the CPU usage since we last checked.
  echo "CPU: $DIFF_USAGE%"
i rephrased the problem, and found a bash script....

it was giving constant updates and printing oddly so i modified it to suit my purpose


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
High CPU utilization on only one CPU out of 4 CPUs makam.sreekanth Linux - Kernel 2 09-03-2009 05:12 AM
cpu utilization and cpu load soltanloo Linux - General 1 06-07-2009 03:19 AM
Total CPU utilization returned by "top" command sanpnair Linux - Newbie 1 05-15-2009 01:19 PM
Interpreting cpu line of top command fshim Linux - Newbie 1 12-22-2008 01:40 PM
Linux desktop GUI tool for CPU utilization and bandwidth utilization karimasif Linux - Software 4 03-03-2008 02:09 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:15 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