You are here: Re: A problem with pcntl_fork « PHP Programming Language « IT news, forums, messages
Re: A problem with pcntl_fork

Posted by petersprc on 11/19/06 23:01

Hi,

pcntl_wait is actually equivalent to calling pcntl_waitpid with -1, so
that will work no problem.

Thomas wrote:
> Hi Peter,
>
> I ended up with this solution:
>
> function sig_handler($signo) {
> switch($signo){
> case SIGCHLD:
> $child = pcntl_wait($status,WNOHANG);
> if($child > 0){
> // Do something
> }
> }
> }
>
> pcntl_signal(SIGCHLD, "sig_handler");
>
> It seems to work like a charm, but it looks a bit different from your
> solutions. You sound like you know A LOT more about this than I do, so
> perhaps I could trouble you for a short explanation on the differences
> between the three solutions? :o)
>
> From my chair you second solution looks like the most "correct" way to
> go. Am I right?
>
> Sincerely,
> Thomas
>
>
> petersprc wrote:
> > Hi,
> >
> > The OS keeps the zombie around in case the parent process eventually
> > decides to retrieve the child's exit status information. You can tell
> > the OS you're not interested and to not keep zombies around using this:
> >
> > pcntl_signal(SIGCHLD, SIG_IGN);
> >
> > You could also trap SIGCHLD and check the child's exit status:
> >
> > function sigchld($signo) {
> > while (($pid = pcntl_waitpid(-1, $status, WNOHANG)) > 0) {
> > echo "Child with PID $pid returned " .
> > pcntl_wexitstatus($status) . ".\n";
> > }
> > }
> >
> > pcntl_signal(SIGCHLD, 'sigchld');
> >

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация