How do I count how many processes are running in Linux?

How do I see how many processes are running in Linux? How can count all running processes in Linux?

A Linux process is nothing but running instance of a program or command. This page explains various commands to count the number of processes running in Linux.

ADVERTISEMENTS

Viewing running processes in Linux

The ps command used to list the currently running processes and their PIDs in Linux and Unix-like systems. At a bare minimum, two processes displayed on the screen. For example, bash and ps might default on Linux when you just type ps command ps
Sample outputs:

  PID TTY          TIME CMD
31043 pts/3    00:00:00 bash
32324 pts/3    00:00:00 ps

Counts for each file in Linux

The wc is an acronym for word count. By default, wc command counts the number of lines, words, and characters in the text. For examples, show the newline counts
echo "line 1" | wc -l
To print the byte counts
echo "Hello" | wc -c
One can print the word counts as follows:
echo "Hello world" | wc -w
Command to count the number of processes running in Linux

Find how many processes are running in Linux

One can use the ps command along with with the wc command to count the number of processes running on your Linux based system by any user. It is best to run the following commands as root user using the sudo command.

Command to count the number of processes running in Linux

The Linux syntax is as follows:
# ps -e | wc -l
To see and count every process on the system using BSD syntax:
# ps axu | wc -l
Want to see and count every process running as vivek (real and effective ID) in user format, run:
$ ps -U vivek -u vivek u | wc -l
Another example for www-data user:
$ ps -U www-data -u www-data u | wc -l
In short to see and count only processes by a certain user naned root, you can use the following command:
sudo ps -U root | wc -l
sudo ps -U root -u root u | wc -l

Next we are going count process IDs of nginx using the following syntax:
ps -C nginx | wc -l
ps -C nginx -o pid= | wc -l

See how many processes are running in Linux
Pass the --no-headers or --no-heading to print no header line at all to get processes count correctly on Linux:
# ps -e --no-headers | wc -l
52
# ps -e | wc -l
53

When count real number of nginx it is a good idea to remove grep command while grepping using ps command:
ps -e --no-headers | grep [n]ginx
ps -e --no-headers | grep [n]ginx | wc -l

Understanding the wc command options

wc optiondescription
-cPrint the byte counts
-mPrint the character counts
-lPrint the newline counts
-wprint the word counts
--helpDisplay the wc command help and exit

Understanding the ps command options

ps optiondescription
-eSelect all processes (GNU/Linux syntax)
auxSelect all processes using BSD syntax
-U userSelect by real user ID (RUID) or name
-u userSelect by effective user ID (EUID) or name
-C cmdlistSelect by command name. This selects the processes whose executable name is given in cmdlist
--no-headersPrint no header line at all. --no-heading is an alias for this option

Conclusion

You learned how to list the number of processes running on the Linux or Unix like system using various command-line options. See the gnu ps help page here.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS

Comments on this entry are closed.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.