Count the number of running processes
The shell command
ps could be used to list most process statistics.
We can use this command piped with
wc to get the number of running processes in Linux, remember to remove the header of output,
-L will also display threads.
$ ps -A --no-headers | wc -l 232 $ ps -AL --no-headers | wc -l 456
If you want to count the processes of a specific user, use the following command:
$ ps -U user1 --no-headers | wc -l 36
If you want to count the number of spawned process by
httpd, these two commands will be your choice:
$ ps -C httpd --no-headers | wc -l 8 $ pgrep httpd | wc -l 8
pgrep is a very useful command to lookup running processes based on name, process ID and other attributes of a process like the user who created the process.
Get the maximum number of processes
You may be curious about the number limit of running processes in a system.
On Linux, you could check the maximum number of processes with the command:
$ cat /proc/sys/kernel/pid_max 32768
$ sysctl kernel.pid_max 32768
Usually, 4194303 is the maximum limit for x86_64 and 32767 for x86. If you want to change the maximum number, you could write to
kernel.pid_max = 4194303
Process number limit per user
The root user doesn’t have a limit on the number of processes,
ulimit -a will show all kinds of limitation of resource for a user.
Normally, a non-root user has a limit on the number of processes. If you want to change the limit on the number of process for a particular user, you need to add an entry in
user1 - nproc 5000