Deep forking?

my class C is to implement a very small shell.

Our shell checks the user input line for internal commands (for example, cd or exit), if none are found, these are forks () and execs () the input line.

I would like to implement reliable forking (this is a way beyond the call of duty for this class, please do not ask me to do my homework, this is more personal research to understand more Linux "internals"). My current approach is this:

t = fork();             
if (t < 0) {            
  if (errno == ENOSYS) {                                
    printf("fork() is not supported on this platform. Minishell will not work.");
    break;
  }
  else if (errno == ENOMEM) {   
    printf("No free kernel memory. Minishell will exit.");
    break;
  }
  else {        
    int try = 0;
    while (t < 0 && try < 10) {
      try++;
      t = fork();
    }
  }
  continue;
}

, ENOSYS , , ENOMEM ( , ;)), . EAGAIN, , fork() .

, , , 1500 , , , . , ? , , .

.

+4
2

, EAGAIN fork. Linux:

EAGAIN fork() .

EAGAIN , RLIMIT_NPROC. , CAP_SYS_ADMIN CAP_SYS_RESOURCE.

ENOMEM, - . , - , , 10 , , .

EAGAIN fork.

, -, ( ..), .

, , fork, .

+5

EAGAIN , /.

, wait . ( ) - , , .

+2

All Articles