note 35746 rejected from function.pcntl-fork by vincent
| From: | vincent@php.net | Date: | Fri, 12 Sep 2003 21:24:46 +0000 |
| Subject: | note 35746 rejected from function.pcntl-fork by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-56415@lists.php.net to get a copy of this message | ||
Note Submitter: daniel@cidadedodireito.com.br
----
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");
}
}
}
?>