CPU Load data

Discussion in 'Linux & BSD' started by onimkron, May 9, 2005.

  1. onimkron

    onimkron OSNN Senior Addict

    Messages:
    414
    Hi all,

    Just starting to get to grips with shell scripting...even though my knowledge of linux is pretty poor itself!

    I want to output the cpu load into terminal, showing user, system, nice and idle. proc/stat contains the data I need, but it's in jiffes- I need the output to be in percentages, similarly to 'top' (but I'm trying not to use that command). I think I need to do some equations to convert the numbers into percentages, but I'm not entirely too sure. Following from that, I'm not even too sure how I could implement that into the script :squareeye:

    Any help will be appreciated :nervous:
     
  2. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    top :p

    Then use grep to grab the parts you want from it.

    man top
    man grep
    man uptime

    uptime can be used for just the CPU load, and the current uptime.
     
  3. onimkron

    onimkron OSNN Senior Addict

    Messages:
    414
    I'm trying not to use that command, but instead, to just get the data from the proc/ directory. I know it sounds odd, but I'm trying to stay as far away as possible from top and ps :)
     
  4. hummunnah

    hummunnah OSNN One Post Wonder

    Messages:
    4
    Hi,

    Im not too sure exactly what you want here but I can give you a simple 'C' script that will convert the jiffies into percentages if you would like.[size=-1]
    [/size]
     
  5. can you attach the C script here :D i wanna see it just to get an idea
     
  6. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA

    google:

    uptime for Linux

    Find the source for it, and look at the code, this is a C program, which you can compile with gcc.