top button
Flag Notify
Site Registration

What is the maximum number of process that can be created in a linux system?

+4 votes
474 views

Lets assume I have a system with RAM of 1GB. and virtual memory is 500MB. That brings to 1.5GB i.e. 1500 MBytes.

I have read somewhere that when I process is created stack of 8MB is associated to that process. So, assuming that any of the process is not allocating any dynamic memory or anything, then does it mean that, Maximum number of process that i can create is 1500/8 and i.e. 187 Process.

Please clarify my understanding,

posted Sep 10, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

You can see the max number of process can be created by a Linux machine by
cat /proc/sys/kernel/pid_max

man proc
// as per the manual page.

/proc/sys/kernel/pid_max (since Linux 2.5.34)
          This file specifies the value at which PIDs wrap  around  (i.e.,
          the  value  in  this  file is one greater than the maximum PID).
          The default value for this file,  32768,  results  in  the  same
          range of PIDs as on earlier kernels.  On 32-bit platforms, 32768
          is the maximum value for pid_max.  On  64-bit  systems,  pid_max
          can be set to any value up to 2^22 (PID_MAX_LIMIT, approximately
          4 million).
answer Sep 11, 2015 by Arshad Khan
Similar Questions
+4 votes

Code to write data in to file example.txt.. which is working fine

// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}

File : filelimit.c below which takes input as the compiled binary of above code
In this code i am setting the file size limit of process to 10 bytes and the above code is trying to write more than 10 bytes. According to below code if a process is trying to write more than 10 bytes to file it should send the signal SIGXFSZ (see more about this here)

It is not sending here... Why??

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

void handler(int sig)
{
    if(sig == SIGXFSZ)
        printf("Inside handler with correct signal\n");
    else
        printf("Inside handler with wrong signal\n");
}


int main(int argc, char const *argv[])
{
    pid_t pid;
    pid = fork();

    if(pid == 0)
    {
        signal(SIGXFSZ, handler);

        char command[256];
        scanf("%s", command);

        int ret;

        struct rlimit rl;
        rl.rlim_cur = 10;
        rl.rlim_max = 10;
        setrlimit (RLIMIT_FSIZE, &rl);

        char *envp[] = { NULL };
        char *argv[] = { command , NULL };
        ret = execve(command, argv, envp);

        while(1);
    }
    else
    {
        printf("%d - %d\n", getpid(), pid);
        signal(SIGXFSZ, handler);
        while(1);
    }
    return 0;
}
+3 votes

Please understand the scenario :

I have an embedded system, on which i do telnet and then i starts i run an application using ./binary_name &.
Now if i close the terminal, and if i do telnet from new terminal then i can see above process is still running.

Now, To check this, i have written a sample program,

#include<stdio.h>
main()
{
    while(1);
}

I just compiled it and i ran it on my linux PC using ./a.out &.
Then i just closed the terminal and from new terminal i checked using ps -elf command this process was killed.

My question is why different behavior for both process. i started both the process in background. Then why?

Any suggestion?

Thanks in advance

0 votes

There are two files.

    #include <stdio.h>
    void fun1(int i)
    {
            int a;
            printf("Enter the number\n");
            scanf("%d",&a);
            if(a==i)
                    printf("Equal\n");
            else
                    printf("Equal\n");
    }

    int main()
    {
        fun1(18);
    }

/* INPUT  */    
    18

What will be in file in OUTPUT file both cases.
Case-1:

./a.out < INPUT  > OUTPUT 

Case-2: Entered value is "18" from key board.

./a.out > output
...