Maximum number of child processes on Unix

I have a question. I just want to know what is the maximum limit on the number of child processes when it is created by a process using the fork () system call? I am using UBUNTU OS (12.04) with the kernel 3.2.0-45-generic.

+4
source share
5 answers

Programmatically,

#include <stdio.h> #include <sys/resource.h> int main() { struct rlimit rl; getrlimit(RLIMIT_NPROC, &rl); printf("%d\n", rl.rlim_cur); } 

where struct rlimit:

 struct rlimit { rlim_t rlim_cur; /* Soft limit */ rlim_t rlim_max; /* Hard limit (ceiling for rlim_cur) */ }; 

From man :

RLIMIT_NPROC

The maximum number of processes (or rather Linux, threads) that can be created for the real user ID of the calling process. When faced with this limit, fork (2) fails with an EAGAIN error.

+2
source

if you need the maximum user process number, this code also works:

 #include "stdio.h" #include "unistd.h" void main() { printf("MAX CHILD ID IS :%ld\n",sysconf(_SC_CHILD_MAX)); } 
+2
source

The number of processes is not a process limit, but a user restriction.

0
source

On Linux, you can use:

 ulimit -u 

to tell you about the maximum processes that the user can perform, and using the -a argument, all user restrictions will be specified.

0
source

There are already answers to get the current maximum value. I would like to add that you can set this limit by making changes to /etc/security/limits.conf

sudo vi /etc/security/limits.conf

Then add this line to the end of this file

hard nproc 1000

You can raise this to any number you want -

nproc is the maximum number of processes that can exist simultaneously on a machine.

0
source

Source: https://habr.com/ru/post/1492957/


All Articles