-2

Including the initial parent process, how many processes are created by the program:

#include <stdio.h>
#include <unistd.h>

int main()
{
     /* fork a child process */
     fork();

     /* fork a child process */
     fork();

     /* and  fork another */
    fork();
    return 0;
}
Mat
  • 202,337
  • 40
  • 393
  • 406
  • @Cristian I would have marked it as duplicated if only I had enough repo there :) – konsolebox Aug 07 '14 at 13:41
  • How would you go about demonstrating the answer? You'd need to add some `printf()` statements; you might use `printf("PID %d\n", (int)getpid());` before, after and between the `fork()` calls, possibly with `fflush(stdout);` calls too (there's a whole other set of questions on what happens if the output is going to terminal vs output is going to file). – Jonathan Leffler Aug 07 '14 at 13:58

1 Answers1

-1

simple answer is :

fork() faild too many processes.

no count is done to check after the retrun of fork() if you are in father or son, so forking will goeis on until you hit nproc, or lack ressources.

Archemar
  • 541
  • 1
  • 12
  • 22