note 35746 added to function.pcntl-fork

From: Date: Fri, 12 Sep 2003 21:22:43 +0000
Subject: note 35746 added to function.pcntl-fork
Groups: php.notes 
Request: Send a blank email to php-notes+get-56414@lists.php.net to get a copy of this message
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 =/ the script is large, so the main pieces of it.. 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.. <? 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 father... if (($n % 100) == 0) { out("[+] giving some time for childs...\n"); sleep(10); $n = 0; out("[+] making more childs ;D\n"); } } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.pcntl-fork.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35746 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35746&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35746&report=yes

« previous php.notes (#56414) next »