14

Htop gives me the following output :

enter image description here

The values didn't change for the last minutes.

So I wonder, what is the difference between "task", "thread" and "running" ?

I had a look to this page : http://www.deonsworld.co.za/2012/12/20/understanding-and-using-htop-monitor-system-resources/ but it skips this specific part :(

From what I know of my server usage, I would say :

  • We have 10 process, which divide in 59 tasks, and 160 threads...

I don't really get the differences between each of these :-/

Any explanations ?

It is also strange because there are tens of processes :

enter image description here

2 Answers 2

6

You almost have it right. :)

There may be dozens of processes (or tasks) listed, but only 10 'threads' are actually 'running' on the CPU. The rest of the processes and threads are 'sleeping' until the OS schedules them for CPU usage.

So, there are 59 tasks, some of which are broken up into 160 threads, but only 10 threads are running on the CPU.

3
  • can we say task = process ? Dec 27, 2016 at 23:06
  • if I do [ ps -axjf | wc -l ] I got the number 253 Dec 27, 2016 at 23:09
  • Is this the same as saying that 10 CPU threads are being used? Because on a machine here with 256 threads I have "Tasks: [...] 256 running", but many of the CPUs in the CPU list are at 0%. Oct 12, 2023 at 7:31
2

htop's tasks are just processes. They are listed in the main window in white (press Shift-H to hide user process threads which are green). To count them with ps you should execute something like ps axjf | grep --invert-match '^[ ]*2 ' | wc --lines, i.e. you have to exclude kernel threads from the ps output (their parent is kthreadd, and because of that their PPID is 2).

Also, you can see at the source code, that tasks are counted as number of all processes and threads minus kernel threads and minus userland threads.

Number of running tasks is calculated by scanning /proc, and at any moment can't be greater then the total number of CPU cores in the system (so it's quite useless number on a low-end system; for example I almost always see "2" on my two-core laptop).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .