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

  • Home
  • SEARCH
  • 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 633629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:12:26+00:00 2026-05-13T20:12:26+00:00

I’d like to monitor the current system-wide CPU usage on a Mac with Python.

  • 0

I’d like to monitor the current system-wide CPU usage on a Mac with Python.

I’ve written some code that starts ‘ps’, and adds up all the values from the ‘%cpu’ column.

def psColumn(colName):
    """Get a column of ps output as a list"""
    ps = subprocess.Popen(["ps", "-A", "-o", colName], stdout=subprocess.PIPE)
    (stdout, stderr) = ps.communicate()
    column = stdout.split("\n")[1:]
    column = [token.strip() for token in column if token != '']
    return column

def read(self):
    values = map(float, psColumn("%cpu"))
    return sum(values)

However, I always get high readings from 50% – 80%, probably caused by the measuring program itself. This CPU usage peak does not register on my MenuMeters or other system monitoring programs. How can I get readings which are more like what MenuMeters would display? (I want to detect critical situations in which some program is hogging the CPU.)

p.s. I have tried psutil, but

psutil.cpu_percent()

always returns 100%, so either it’s useless for me or I am using it wrongly.

  • 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-13T20:12:26+00:00Added an answer on May 13, 2026 at 8:12 pm

    For detecting critical situations when some program is hogging the CPU perhaps looking at load average is better? Take a look at “uptime” command.

    Load average number tells you how many processes on average are using or waiting on CPU for execution. If it is close to or over 1.0, it means the system is constantly busy with something. If load average is constantly raising, it means that system cannot keep up with the demand and tasks start to pile up. Monitoring load average instead of CPU utilization for system “health” has two advantages:

    • Load averages given by system are already averaged. They don’t fluctuate that much so you don’t get that problem with parsing “ps” output.
    • Some app may be thrashing disk and rendering system unresponsive. In this case CPU utilization might be low, but load average would still be high indicating a problem.

    Also monitoring free RAM and swap would be a good idea.

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

Sidebar

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.