Prak
Prak

Reputation: 1069

Maximum number of child process in Unix

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.

Upvotes: 6

Views: 10631

Answers (5)

Lidong Guo
Lidong Guo

Reputation: 2857

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));
}

Upvotes: 2

Dayal rai
Dayal rai

Reputation: 6606

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.

Upvotes: 0

mohit
mohit

Reputation: 6044

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.

Upvotes: 4

Shafik Yaghmour
Shafik Yaghmour

Reputation: 158469

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.

Upvotes: 0

hivert
hivert

Reputation: 10667

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

Upvotes: 0

Related Questions