Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 854125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:52:22+00:00 2026-05-15T07:52:22+00:00

I am trying to get total cpu usage in %. First I should start

  • 0

I am trying to get total cpu usage in %. First I should start by saying that “top” will simply not do, as there is a delay between cpu dumps, it requires 2 dumps and several seconds, which hangs my program (I do not want to give it its own thread)

next thing what I tried is “ps” which is instant but always gives very high number in total (20+) and when I actually got my cpu to do something it stayed at about 20…

Is there any other way that I could get total cpu usage? It does not matter if it is over one second or longer periods of time… Longer periods would be more useful, though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:52:22+00:00Added an answer on May 15, 2026 at 7:52 am

    cat /proc/stat

    http://www.linuxhowtos.org/System/procstat.htm

    I agree with this answer above. The cpu line in this file gives the total number of "jiffies" your system has spent doing different types of processing.

    What you need to do is take 2 readings of this file, seperated by whatever interval of time you require. The numbers are increasing values (subject to integer rollover) so to get the %cpu you need to calculate how many jiffies have elapsed over your interval, versus how many jiffies were spend doing work.

    e.g.
    Suppose at 14:00:00 you have

    cpu 4698 591 262 8953 916 449 531

    total_jiffies_1 = (sum of all values) = 16400

    work_jiffies_1 = (sum of user,nice,system = the first 3 values) = 5551

    and at 14:00:05 you have

    cpu 4739 591 289 9961 936 449 541

    total_jiffies_2 = 17506

    work_jiffies_2 = 5619

    So the %cpu usage over this period is:

    work_over_period = work_jiffies_2 – work_jiffies_1 = 68

    total_over_period = total_jiffies_2 – total_jiffies_1 = 1106

    %cpu = work_over_period / total_over_period * 100 = 6.1%

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the total amount of Milliseconds ( not the millis field)
I'm trying to get the total count of employee ids so that I can
I'm trying to get total salary for the whole company by: NSNumber *totalSalary =
I'm trying to get the total of calc.transport Table 3_product_folder contains duplicate values (column
I'm trying to find a way to get the total number of child nodes
So i am trying get 2 div-containers which both should contain centered text (Both
I am trying to get the total count and total sum per salesperson but
basically I am trying to get the total of (facebook) likes for an external
I'm trying to get the total height of a page using JavaScript so I
Background: I'm trying to get a total line count of all of the code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.