I have a question going in my mind. I just want to know what is the maximum limit on the number of child process when it is created by a process by using fork() system call? I am using UBUNTU OS (12.04) with kernel 3.2.0-45-generic.
-
4`ulimit -u` will tell you the max number of processes for a user. – Shafik Yaghmour Jul 23 '13 at 13:19
-
But is it the the same as the maximum number of child process a process can create. As a user , I can run multiple process at the same time in the background without creating any child process. – Prak Jul 23 '13 at 13:25
-
It is the same limit regardless. – Shafik Yaghmour Jul 23 '13 at 13:30
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 is:
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, more precisely on Linux, threads) that can be created for the real user ID of the calling process. Upon encountering this limit, fork(2) fails with the error EAGAIN.
if you need the max process number of user limit , this code also work:
#include "stdio.h"
#include "unistd.h"
void main()
{
printf("MAX CHILD ID IS :%ld\n",sysconf(_SC_CHILD_MAX));
}

- 2,817
- 2
- 19
- 31
-
2Please don't use `void main()` unless you're on Windows, where you probably can't use `sysconf()`. See [What should `main()` return in C and C++?](http://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c/18721336#18721336). Also, the standards use `#include
` and `#include – Jonathan Leffler Jul 22 '14 at 02:21` and you should too.
On Linux you can use:
ulimit -u
to tell you the max processes a user can run and using -a
argument will tell you all the user limits.

- 154,301
- 39
- 440
- 740
Answers are already there to get current maximum value.I would like to add that you can set this limit by making change in /etc/security/limits.conf
sudo vi /etc/security/limits.conf
Then add this line to the bottom of that file
hard nproc 1000
You can raise this to whatever number you want -
nproc
is maximum number of processes that can exist simultaneously on the machine.

- 6,548
- 22
- 29