title: Fork error: resource temporarily unavailable
body: <p>I have written this code in a project based on the client-server model but in one of my files I have this error: fork error resource temporarily unavailable.
  this is the 
  <em>Code</em>:</p>
  
  <pre><code>#include "LibreriaFunzioni.c"
  int main (int argc , char *argv[])
  {
      int list_fd,list_fd2,fd,fd2,SocketFiglioSede;
      int i;
      struct sockaddr_in s_addr,s_addr2,c_addr,c_addr2;
      char buffer [4096];
      socklen_t len,len2;
      pid_t pid_Admin,pid_Client,pid;
      int logging =1,N_Portate;
      PORTATA *Menu = NULL;
      ORDINE Ordine;
      ORDINE OrdineID;
  
      Menu = CaricaMenuPortate(&amp;N_Portate);
   //------------------ADMIN--------------------------------------
      /* create socket ADMIN*/
      if ( (list_fd = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0) {
          perror("Socket creation error");
          exit(1);
      }
  
      /* initialize address */
      memset((void *)&amp;s_addr, 0, sizeof(s_addr));   /* clear server address */
      s_addr.sin_family = AF_INET;                  /* address type is INET */
      s_addr.sin_port = htons(2700);                   /* echo port is 7 */
      s_addr.sin_addr.s_addr = htonl(INADDR_ANY);   /* connect from anywhere */
  
      /* bind socket */
      if (bind(list_fd, (struct sockaddr *) &amp;s_addr, sizeof(s_addr)) &lt; 0) {
          perror("bind error");
          exit(1);
      }
  
      /* main body */
      if (listen(list_fd, 4096) &lt; 0) {
          perror("listen error");
          exit(1);
      }
  //-----------------------CLIENT-------------------------------------
      /* create socket CLIENT */
      if ( (list_fd2 = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0) {
          perror("Socket creation error");
          exit(1);
      }
  
      /* initialize address */
      memset((void *)&amp;s_addr2, 0, sizeof(s_addr2));   /* clear server address */
      s_addr2.sin_family = AF_INET;                  /* address type is INET */
      s_addr2.sin_port = htons(2800);                   /* echo port is 7 */
      s_addr2.sin_addr.s_addr = htonl(INADDR_ANY);   /* connect from anywhere */
  
      /* bind socket */
      if (bind(list_fd2, (struct sockaddr *) &amp;s_addr2, sizeof(s_addr2)) &lt; 0) {
          perror("bind error");
          exit(1);
      }
  
      /* main body */
      if (listen(list_fd2, 4096) &lt; 0) {
          perror("listen error");
          exit(1);
      }
  
  
  
  
  
      while(1){
        //---------GESTIONE ADMIN--------------------------------------------
          pid_Admin = fork();
          if(pid_Admin &lt; 0) {
              perror (" fork error ");
              exit ( -1);
          }
          if(pid_Admin == 0)
          {
              len = sizeof(c_addr);
              if ((fd = accept(list_fd, (struct sockaddr *) &amp;c_addr, &amp;len)) &lt; 0) {
                  perror("accept error");
                  exit(1);
              }
  
              close ( list_fd );
              if(logging)
              {
                  inet_ntop(AF_INET, &amp;c_addr.sin_addr, buffer, sizeof(buffer));
                  printf("\nNUOVA SESSIONE con admin IP:PORTA =&gt; %s:%d su socket =&gt; %d\n", buffer, ntohs(c_addr.sin_port), fd);
                  SpedisciTabella(fd, N_Portate, Menu);
              }
  
              close(fd);
              exit (0);
          }
       //-------------GESTIONE CLIENT----------------------------------------
          pid_Client = fork();
          if(pid_Client &lt; 0) {
              perror (" fork error ");
              exit ( -1);
          }
          if(pid_Client == 0)
          {
              len2 = sizeof(c_addr2);
              if ((fd2 = accept(list_fd, (struct sockaddr *) &amp;c_addr2, &amp;len2)) &lt; 0) {
                  perror("accept error");
                  exit(1);
              }
  
              close ( list_fd2 );
              if(logging)
              {
                  inet_ntop(AF_INET, &amp;c_addr.sin_addr, buffer, sizeof(buffer));
                  printf("\nNUOVA SESSIONE con client IP:PORTA =&gt; %s:%d su socket =&gt; %d\n", buffer, ntohs(c_addr.sin_port), fd);
                  SpedisciTabella(fd2, N_Portate, Menu);
              }
              pid = fork();
              if((pid&lt;0))
              {perror ("Errore nella fork()"); exit (-1);}
              if(pid==0)
              {
                  read(fd2, &amp;Ordine, sizeof(Ordine));
                  if(Ordine.sede == 1){
                      SocketFiglioSede = ConnettiAlServer("127.0.0.1", 2200);
                      FullWrite(SocketFiglioSede, &amp;Ordine, sizeof(Ordine));
                      read(SocketFiglioSede,&amp;Ordine, sizeof(Ordine));
                      printf("\nID %d",Ordine.ID);
                      printf("\nCOD %d",Ordine.SceltaP);
                      FullWrite(fd2, &amp;Ordine, sizeof(Ordine));
                      printf("\n** (PADRE) Disconnetti client su socket ==&gt; %d **\n", fd2);
                      close(SocketFiglioSede); /
                      exit(0);
                  }// Chiudi processo
  
                  if(Ordine.sede == 2){
                      SocketFiglioSede = ConnettiAlServer("127.0.0.1", 2300);
                      FullWrite(SocketFiglioSede, &amp;Ordine, sizeof(Ordine));
                      read(SocketFiglioSede,&amp;Ordine, sizeof(Ordine));
                      FullWrite(fd2, &amp;Ordine, sizeof(Ordine));
                      close(SocketFiglioSede);
                      printf("\n** (PADRE) Disconnetti client su socket ==&gt; %d **\n", fd2);
                      exit(0);
                  }// Chiudi processo
  
              }
              close(fd2);
              exit (0);
          }
      }
      exit (0);
  }
  </code></pre>
  
  <p>I try to correct the code but I fail all the time.
  Can you help me?</p>