Results 1 to 7 of 7

Thread: Command to get CPU core usage

  1. #1
    Join Date
    Jun 2009
    Location
    0:0:0:0:0:0:0:1
    Beans
    4,669
    Distro
    Xubuntu

    Command to get CPU core usage

    What is the command to get the CPU usage of core X (preferably as a percentage)
    Is there something i can cat in /sys/ like i can for the governor?
    Last edited by pqwoerituytrueiwoq; October 20th, 2012 at 05:39 PM.
    Laptop: ASUS A54C-NB91 (Storage: WD3200BEKT + MKNSSDCR60GB-DX); Desktop: Custom Build - Images included; rPi Server
    Putting your Networked Printer's scanner software to shame PHP Scanner Server
    I frequently edit my post when I have the last post

  2. #2
    Join Date
    Jul 2007
    Location
    Magic City of the Plains
    Beans
    Hidden!
    Distro
    Xubuntu Development Release

    Re: Command to get CPU core usage

    htop can do this, it shows the number of cores and their use by percentage by default.

  3. #3
    Join Date
    Jun 2009
    Location
    0:0:0:0:0:0:0:1
    Beans
    4,669
    Distro
    Xubuntu

    Re: Command to get CPU core usage

    i need to get it in a script, any idea where htop gets that info?
    Laptop: ASUS A54C-NB91 (Storage: WD3200BEKT + MKNSSDCR60GB-DX); Desktop: Custom Build - Images included; rPi Server
    Putting your Networked Printer's scanner software to shame PHP Scanner Server
    I frequently edit my post when I have the last post

  4. #4
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: Command to get CPU core usage

    If you install the sysstat package you can use the mpstat command and do a bit of awk'ery to get your value:
    Code:
    rob@arch:~$ mpstat | awk '$12 ~ /[0-9.]+/ { print 100 - $12 }'
    5.29
    The above is the total for all cores, if you want the value for a specific core you can add the -P switch:
    Code:
    rob@arch:~$ mpstat -P 0 | awk '$12 ~ /[0-9.]+/ { print 100 - $12 }'
    9.42
    Cheesemill

  5. #5
    Join Date
    Jul 2007
    Location
    Magic City of the Plains
    Beans
    Hidden!
    Distro
    Xubuntu Development Release

    Re: Command to get CPU core usage

    No idea, sorry.

  6. #6
    Join Date
    Jun 2009
    Location
    0:0:0:0:0:0:0:1
    Beans
    4,669
    Distro
    Xubuntu

    Re: Command to get CPU core usage

    mpstat -P 0 is far from accurate
    Idle:
    Code:
    Linux 3.6.2-030602-generic (Quantal-Desktop)     10/20/2012     _x86_64_    (4 CPU)
    
    01:04:56 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
    01:04:56 PM    0    3.70    2.05    3.04    1.38    0.00    0.07    0.00    0.00   89.75
    prime 95 torture test:
    Code:
    Linux 3.6.2-030602-generic (Quantal-Desktop)     10/20/2012     _x86_64_    (4 CPU)
    
    01:06:11 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
    01:06:11 PM    0    3.81    2.21    3.09    1.31    0.00    0.07    0.00    0.00   89.51
    Laptop: ASUS A54C-NB91 (Storage: WD3200BEKT + MKNSSDCR60GB-DX); Desktop: Custom Build - Images included; rPi Server
    Putting your Networked Printer's scanner software to shame PHP Scanner Server
    I frequently edit my post when I have the last post

  7. #7
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: Command to get CPU core usage

    You're absolutely correct, I've just done some testing of my own and it was way off.
    I'm not sure where it gets its values from then.
    Cheesemill

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •