264

In ps xf

26395 pts/78   Ss     0:00  \_ bash
27016 pts/78   Sl+    0:04  |   \_ unicorn_rails master -c config/unicorn.rb                                           
27042 pts/78   Sl+    0:00  |       \_ unicorn_rails worker[0] -c config/unicorn.rb                                        

In htop, it shows up like: htop showing multiple unicorn_rails lines

Why does htop show more process than ps?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Cheng
  • 6,641
  • 2
    http://superuser.com/questions/118086/why-are-there-many-processes-listed-under-the-same-title-in-htop | http://stackoverflow.com/questions/11017597/htop-showing-multiple-java-processes-with-different-pids | http://askubuntu.com/questions/17047/in-htop-i-sometimes-see-lists-of-64-processes-identical-for-all-but-the-pid-w – Ciro Santilli OurBigBook.com Sep 18 '16 at 07:44

3 Answers3

364

By default, htop lists each thread of a process separately, while ps doesn't. To turn off the display of threads, press H, or use the "Setup / Display options" menu, "Hide userland threads". This puts the following line in your ~/.htoprc or ~/.config/htop/htoprc (you can alternatively put it there manually):

hide_userland_threads=1

(Also hide_kernel_threads=1, toggled by pressing K, but it's 1 by default.)

Another useful option is “Display threads in a different color” in the same menu (highlight_threads=1 in .htoprc), which causes threads to be shown in a different color (green in the default theme).

In the first line of the htop display, there's a line like “Tasks: 377, 842 thr, 161 kthr; 2 running”. This shows the total number of processes, userland threads, kernel threads, and threads in a runnable state. The numbers don't change when you filter the display, but the indications “thr” and “kthr” disappear when you turn off the inclusion of user/kernel threads respectively.

When you see multiple processes that have all characteristics in common except the PID and CPU-related fields (NIce value, CPU%, TIME+, ...), it's highly likely that they're threads in the same process.

  • 6
    Any clue about why this is the default? Why is that relevant? It seems like adding noise but I guess there is a good reason. – tuxayo Mar 23 '18 at 10:37
  • 5
    @tuxayo I was curious too and found this: https://github.com/htop-dev/htop/issues/99#issuecomment-748142128 tl;dr it was a kind of a philosophical choice. – Shautieh Feb 02 '21 at 01:37
4

For me, on a more-or-less current arch linux system, ps xf shows me only the processes owned by my user ID. htop shows me all processes. Try ps -ef for a list of all processes, or perhaps ps -ejH to get a child/parent relationship listing.

0

htop is also showing processes that have ended. This is great, so you can see short-lived processes and what resources they might have consumed. If you exit htop and restart it, you'll see they have disappeared. I can't figure out a way to make htop drop historical processes without restarting, so maybe there's a way.

MikeB
  • 101