15

I am running a webserver with apache2 and ubuntu. Using ps I can see only a few apache processes running:

ps aux | grep apache

However if I htop, I can see loads of apache2 processes running. About 2 dozen. Why the difference?

Amandasaurus
  • 30,211
  • 62
  • 184
  • 246
  • apache2 is a semi-threaded model vs. the original apache series. Top doesn't do threads, neither does ps - but htop does. – Avery Payne Nov 19 '09 at 18:49

5 Answers5

18

HTop is showing all the processes and their threads whereas ps aux only shows the processes. Press F5 in htop to create a hierarchal view of the processes and their threads. It will make more sense.

Luke
  • 3,756
  • 7
  • 35
  • 39
  • You can hide threads in htop. Press F2 to go the settings, go to Display Options, and select "Hide kernel threads" and "Hide userland process threads". To still show the threads, but in a different color, select "Display threads in a different color". – JW. May 09 '17 at 11:51
12

sweimann's answer is correct.

Additionally you can make ps(1) behave in the same way by using the H flag which will display threads as if they were processes.

Apparently the same key will also toggle off such behaviour in htop.

Dan Carley
  • 25,189
  • 5
  • 52
  • 70
6

I don't know htop, but maybe it displays threads as separate processes and you have configured apache with a multithreaded worker?

Sven
  • 97,248
  • 13
  • 177
  • 225
3

In htop, you can disable this behavior by pressing F2, then go to "Display options", then mark "Hide userland threads". Optionally you may find "Hide kernel threads" useful too.

Juliano
  • 5,402
  • 27
  • 28
2

To highlight the difference between processes and threads in htop:

  1. press F2
  2. select "Display options"
  3. enable "Display threads in a different color"
ESV
  • 155
  • 5