well... playing with fork() in a phpcli script, i got some troubles with
childs... anybody knows how to dont get zombies/defuncts with SIGCHLD and
SIGCLD ignoring ? dont worked for me =/

i dont want to know how many childs are running, or if they terminated or
not... i want only to make childs :D
ignoring SIGCHLD in perl works finely... is there anything about the
"phped-layer" to syscalls access ? duh..

comments are welcome =)

[]'s
Daniel Souza

<?
   declare (ticks = 1);

   //original sighangler, not used anymore... i know :)
   function sig_handler($signo)
   {
      out("[+] SIG: $signo\n");
      $pid = pcntl_waitpid(-1, &$status, WNOHANG);
      if ($signo == SIGCHLD)
         out("[+] SIGCHLD PID:$pid\n");
      if ($signo == SIGCLD)
         out("[+] SIGCLD PID: $pid\n");
      //posix_kill($pid, SIGTERM);
   }

   pcntl_signal(SIGCLD, SIG_IGN);
   pcntl_signal(SIGCHLD, SIG_IGN);

   $n = 0;
   while (1)
   {
      $n++;
      $pid = pcntl_fork();
      if ($pid == -1)
      {
         out("[+] error in fork.\n");
         exit(-1);
      }
      if ($pid == 0)
      {
         // child...
         $pid           = posix_getpid();
         out("[+] im the number $n !!!\n");
         // do some job...
         exit(0);
      }
      else
      {
          // im parent...
          if (($n % 100) == 0) // we wait 10sec to create another childs
          {
              out("[+] giving some time for childs...\n");
              sleep(10);
              $n = 0;
              out("[+] making more childs ;D\n");
          }
      }
  }

?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to