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.
A parent process may have multiple child processes, but a child process only one parent process. On the success of a fork() system call: The Process ID (PID) of the child process is returned to the parent process. 0 is returned to the child process.
The kernel. pid_max value of 131072 above means the kernel can execute a maximum of 131,072 processes simultaneously. The vm. max_map_count value of 65530 above is the maximum number of memory map areas a process may have.
On some Linux distributions (Redhat Enterprise Linux Server/CentOS 6.0 or later), the default maximum number of user processes is set to 1024, which is considerably lower than the same parameter on older distributions (e.g., RHEL/CentOS 5. x).
Using some conditions we can generate as many child process as needed.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With