56

What is the maximum limit to the number of processes possible in a linux system? How can we find it ?

amit
  • 175,853
  • 27
  • 231
  • 333
kdexter
  • 569
  • 1
  • 5
  • 5
  • 1
    Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Dec 16 '17 at 00:33

5 Answers5

47

Your kernel should export this information in procfs:

cat /proc/sys/kernel/pid_max

This is the maximum number of unique process identifiers your system can support.

Since it is a file, /proc/sys/kernel/pid_max can be inspected from any capable programming language.

trent
  • 25,033
  • 7
  • 51
  • 90
  • 2
    this may be true, but in most nice distros this is limited by /etc/security/limits.conf which can filter max number of processes on user/group/domain basis. – Tomas Pruzina Feb 20 '12 at 13:27
  • 1
    `ulimit` might limit the max per-user processes to less than the maximum pid, and from a bit of Googling, there's other limitations in play as well (but I couldn't find any definitive sources to confirm, such as LKML or a well known Dev posting it). – Kitsune Feb 20 '12 at 13:28
  • 1
    `int fd = read("/proc/sys/kernel/pid_max");` is not valid, nor is it valid for any other file. – user253751 Jul 10 '16 at 12:52
  • @immibis I edited out the bogus C; hopefully my edit will be approved soon. – Michael Wolf Aug 30 '17 at 17:29
20

sysctl kernel.pid_max

or

cat /proc/sys/kernel/pid_max

As suggested by Ninefingers.

For completeness, you can change it temporarily by writing to /proc/syskernel/pid_max or permanently by adding:

kernel.pid_max = 4194303

to /etc/sysctl.conf. 4194303 is the maximum limit for x86_64 and 32767 for x86.

Lester Cheung
  • 1,964
  • 16
  • 17
16

Short answer to your question : Number of process possible in the linux system is UNLIMITED.

But there is a limit on number of process per user(except root who has no limit).

And you can check your user limits with below command (apposite to "max user processes").

$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 256447
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 128000
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 500000
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

If you want to increase the limit on number of process for a particular user(for eg: hadoop ) , you need to make below entry in /etc/security/limits.conf

hadoop - nproc 500000
Ankit Singhal
  • 834
  • 7
  • 8
5

kernel.pid_max is a limiting factor, but at least as important is kernel.threads-max. It's worth noting that the default nproc ulimit for each user is kernel.threads-max divided by two, and that every thread counts toward a user's nproc limit. Thus, ps -u $USER may make it appear that a user has not exhausted their nproc limit, but ps -L -u $USER could tell a very different story.

Tombart
  • 30,520
  • 16
  • 123
  • 136
Andy Grimm
  • 406
  • 4
  • 6
0

Did you mean that a mongodb process can only create with max nproc = threads-max / 2 ?

Because i'm trying to increase nproc as unlimited.

I tried to put limits on /etc/security/limits.conf as like this: mongodb soft nproc unlimited mongodb hard nproc unlimited mongodb soft nofile 50000 mongodb hard nofile 50000 mongodb soft sigpending unlimited mongodb hard sigpending unlimited However it didn'r reflect on mongodb process even after complete reboot.

Then i tried to put ulimit -u unlimited command to /etc/init.d/mongodb but after i tried to start with this file i got

/etc/init.d/mongodb: 67: ulimit: Illegal option -u

error. Is this kernel.threads-max is limiting mongodb max process count?

hardc0der
  • 449
  • 2
  • 7
  • 13