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?

up vote 1 down vote accepted

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.

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

Fork count since last boot:

vmstat -f

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.