8

How does one find out the true number of processes that is running on your system? A number of articles mention using ps in order to count the number of processes. But recently I looked at cat /proc/stat, and it outputted:

cpu  972 0 1894 189609 236 26 490 0 0 0
cpu0 972 0 1894 189609 236 26 490 0 0 0
intr 101595 157 10 0 0 0 0 0 0 3 0 0 0 136 0 0 0 1406 0 0 14936 934 19133 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ctxt 244344
btime 1405754990
processes 3912
procs_running 3
procs_blocked 0
softirq 122778 0 48263 439 15599 19037 0 1 0 7405 32034

It shows the number of processes as 3912. Using something like ps -A --no-headers | wc -l only shows 173 processes.

Why does /proc/stat show so many more processes (an increase of 3739 processes)? Who is giving the right number?

2 Answers 2

14

Look at the documentation for proc(5), and you'll see this for the processes field:

Number of forks since boot.

So it's simply not the number you're looking for. ps will give you that as you already know, counting the directories with only numbers in their name under /proc is another approach.

1
  • Yea, another resource told me the it was the number of processes. Jul 19, 2014 at 8:31
12

Depending on whether you want to include threads or not, add the -L option to your ps command:

$ ps -A --no-headers | wc -l
359
$ ps -AL --no-headers | wc -l
967

Threads are not listed separately by ps by default. The point of threads is that they are multiple threads of execution inside one process address space.

2
  • Threads are not considered separate processes? Jul 19, 2014 at 12:34
  • 3
    No - that's the point of threads. They are multiple threads of execution inside one process address space. Jul 19, 2014 at 12:36

You must log in to answer this question.

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