Linux Increase Process Identifiers Limit with /proc/sys/kernel/pid_max

Yesterday I wrote about increasing local port range with net.ipv4.ip_local_port_range proc file. There is also /proc/sys/kernel/pid_max file, which specifies the value at which PIDs wrap around (i.e., the value in this file is one greater than the maximum PID). The default value for this file, 32768, results in the same range of PIDs as on earlier kernels (<=2.4). The value in this file can be set to any value up to 2^22 (PID_MAX_LIMIT, approximately 4 million).
Increasing the value will help on large Linux system or clusters to ease process identification and process management. You can easily prevent fork() failures error message with this hack.

Display Current Process Identifiers Limit On a Linux Based Systems

Type the following command at shell prompt:
$ sysctl kernel.pid_max
$ cat /proc/sys/kernel/pid_max
$ sysctl kernel.pid_max
Sample outputs:

kernel.pid_max = 32768

Allow for more PIDs on a Linux based systems

Type the following command:
# sysctl -w kernel.pid_max=4194303
# echo 4194303 > /proc/sys/kernel/pid_max

You need to append the following config directive to your /etc/sysctl.conf file:
kernel.pid_max = 4194303

Please note that this hack is only useful for a large and busy server; don’t try this on an old kernel or on desktop systems.

See also
  • Man pages – proc(5)

# Additional correction by Mæja Stefansson; Editing by VG – log #

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig 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 VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Ole Tange Aug 25, 2014 @ 9:07

    Why is this not default?

    On a non-busy system what penalty do you pay by raising the limit to the max?

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum