htop isn't returning CPU or memory usage!?

80

26

I think that top is great application to monitor a Linux system. I really like it, but top doesn't look so good on Mac. I know that Mac have a system monitor to do it, but I prefer using a terminal.

I have installed htop by running:

brew install htop.

Here is what it looks like:

PID USER     PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
    1 0          0   0     0     0     0 ?  0.0  0.0  0:00.00 (launchd)
   10 0          0   0     0     0     0 ?  0.0  0.0  0:00.00 (kextd)
   11 0          0   0     0     0     0 ?  0.0  0.0  0:00.00 (UserEventAgent)
   12 65         0   0     0     0     0 ?  0.0  0.0  0:00.00 (mDNSResponder)

The problem is that both CPU and MEM aren't returning the real values of either on my system.

Has anyone else experienced this? Or, could some one point me in the right direction?

Yuan He

Posted 2011-09-22T15:54:53.290

Reputation: 913

Answers

92

I have the same problem so I check the recipe.

$ brew edit htop

Then I check this part of the recipe:

def caveats; <<-EOS.undent
    For htop to display correctly all running processes, it needs to run as root.
    If you don't want to `sudo htop` every time, change the owner and permissions:
    cd #{bin}
    chmod 6555 htop
    sudo chown root htop
EOS

So just type sudo htop and you will see CPU and MEM.

matiskay

Posted 2011-09-22T15:54:53.290

Reputation: 1 035

4This is helpful for those who installed with macports as well; for me, I don't know why, but sudo htop didn't work. htop was installed in /bin, so I cd'd there and ran chmod 6555 htop && sudo chown root htop. Now htop works fine. – Brian McCutchon – 2014-09-29T20:22:38.223

1@AB not anymore, they changed it. – Dalibor Filus – 2015-04-06T20:11:26.953

4This solution allows any user to kill any other user's (or root's) processes. Is there a way to allow htop to read CPU and MEM without allowing it to modify the system? – Max – 2015-09-02T22:56:32.450

If you want to modify htop wherever it's installed, use chmod 6555 "$(which htop)" – BallpointBen – 2017-06-19T13:05:48.320

18You can use brew info htop to see caveats content – A B – 2013-03-29T20:36:06.887

20

From my brew info:

You can either run the program via `sudo` or set the setuid bit:

  sudo chown root:wheel /usr/local/Cellar/htop-osx/0.8.2.2/bin/htop

  sudo chmod u+s /usr/local/Cellar/htop-osx/0.8.2.2/bin/htop

This worked to ensure that I don't need to run htop as sudo

Ivan Suftin

Posted 2011-09-22T15:54:53.290

Reputation: 301

6

Here is an alternative for those who don't want to muck with the permissions and still avoid typing sudo htop in preference to just htop:

  1. Install with brew: brew install htop
  2. Allow sudo htop to run without sudo password
    1. Run sudo visudo to open the sudoers file in an editor
    2. Add this to the config file: %admin ALL=(ALL) NOPASSWD: /usr/local/bin/htop
    3. Save the file and exit (:wq most likely)
  3. Add the following alias to your shell rc file (example is for ~/.bashrc or ~/.profile): alias htop='sudo htop'

Sukima

Posted 2011-09-22T15:54:53.290

Reputation: 205

0

Note that for the latest versions of htop to function correctly on OS X, it is not sufficient to "bless" htop with chmod 6555 htop and sudo chown htop - while htop will run, the output will differ between htop and sudo htop.

Here's a screenshot of the "blessed" htop instance, invoked as htop:

enter image description here

and here's a picture of it running as sudo htop:

enter image description here

As you can see, the non-sudo-invoked htop displays significantly less information.

The correct answer was presented by @Sukima; it is unfortunately required to alias htop to sudo htop. For command line users, typing in the password at the prompt is second nature and I think for most of us it's forgetting to launch htop as sudo that is the problem rather than being required to type in the password. I highly advise against allowing sudo htop to run without a password prompt, but if you do wish to do so, the best approach is to allow a single, named user to launch htop (and only htop) without a password (though this is a huge vulnerability since htop is powerful and extensible and can run external commands, which means whoever runs htop as sudo can do anything):

sudo visudo
# add the line below somewhere in the editor
YOURUSERNAME ALL=(ALL) NOPASSWD: /usr/local/bin/htop
# save and exit

Mahmoud Al-Qudsi

Posted 2011-09-22T15:54:53.290

Reputation: 3 274