0

How do I get the number of processes that have been created since the last boot on a Linux machine?

I want to get it from a C++ program. Which proc file stores it?

3 Answers 3

2

That would be in /proc/stat:

The "processes" line gives the number  of processes and threads created, which
includes (but  is not limited  to) those  created by  calls to the  fork() and
clone() system calls.

See file Documentation/filesystems/proc.txt in your kernel source tree for more information about the contents of /proc/stat.

1

Remember to never discount the Linux man pages. I am putting a link below, to the one for /proc.

Proc man

To add to the answer given by Sami Laine, According to the above linked page, /proc/stat has a common entry:

processes 86031
                     Number of forks since boot.

As a side note(slightly off subject), if you are looking to see this data on a SPECIFIC process, and not "in general", you should use, /proc/[pid]/status which:

Provides much of the information in /proc/[pid]/stat and
              /proc/[pid]/statm in a format that's easier for humans to
              parse.
1

Fork count since last boot:

vmstat -f

You must log in to answer this question.

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