downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

pcntl_wexitstatus> <pcntl_wait
[edit] Last updated: Fri, 23 Mar 2012

view this page in

pcntl_waitpid

(PHP 4 >= 4.1.0, PHP 5)

pcntl_waitpidBir çocuk sürecin çıkmasını bekler ve durum kodunu döndürür

Açıklama

int pcntl_waitpid ( int $pid , int &$durum [, int $seçenekler = 0 ] )

pid ile belirtilen çocuk süreç çıkana veya sonlandırıcı bir sinyal alana ya da bir sinyal eylemcisi çağrılana kadar çalışmakta olan sürecin çalışmasını askıya alır.

pid ile belirtilen çocuk zaten çıkmışsa (yani bir zombi süreçse) işlev beklemeden döner. Çocuk sürecin kullandığı sistem özkaynakları serbest bırakılır. Sisteminizde waitpid'in nasıl çalıştığı hakkında ayrıntılı bilgi edinmek için waitpid(2) kılavuz sayfasına bakınız.

Değiştirgeler

pid

pid değeri şunlardan biri olabilir:

pid için olası değerler
< -1 Süreç grup kimliği pid'in mutlak değeriyle eşleşen çocuk süreç için beklenir.
-1 Herhangi bir çocuk süreç için beklenir; bu, wait işlevinin davranışıyla aynıdır.
0 Süreç grup kimliği çağıran sürecinkiyle aynı olan çocuk süreç için beklenir.
> 0 Süreç grup kimliği pid ile eşleşen çocuk süreç için beklenir.

Bilginize:

pid değiştirgesine -1 belirtmek, (seçenekler haricinde) pcntl_wait() işlevselliğine denktir.

durum

pcntl_waitpid() işlevi durum değiştirgesinde şu işlevler ile değerendirilmek üzere durum bilgisini saklar: pcntl_wifexited(), pcntl_wifstopped(), pcntl_wifsignaled(), pcntl_wexitstatus(), pcntl_wtermsig() ve pcntl_wstopsig().

seçenekler

Değeri aşağıdaki küresel sabitlerin bitsel VEYAlanmışıdır:

Olasıseçenekler
WNOHANG Çıkmış çocuk süreç yoksa hemen dön.
WUNTRACED Durumu raporlanmamış ve durmuş çocuklar varsa dön.

Dönen Değerler

Çocuk süreç çıkmışsa süreç kimliği, hata oluşmuşsa -1, WNOHANG kullanılmış ama ortada bir çocuk süreç yoksa 0 ile döner.

Ayrıca Bakınız



pcntl_wexitstatus> <pcntl_wait
[edit] Last updated: Fri, 23 Mar 2012
 
add a note add a note User Contributed Notes pcntl_waitpid
brian dot ngure at gmail dot com 08-Jul-2009 08:03
Please note that you must use bitwise OR | in the following:

"The value of options is the value of zero or more of the following two global constants OR'ed together"

i.e.

WNOHANG | WUNTRACED
tunderzone at gmail dot com 25-Jun-2009 06:26
A better way to do this and not end up having zombie processes until all child processes ends is like this:

<?php
        $i
= 0;
       
$starttime = microtime(TRUE);
       
$pid_arr = array();
        while (
$i < intval($argv[1]))
        {
           
$pid = pcntl_fork();
            if (
$pid == -1)
            {
                die(
'could not fork');
            }
            else
            {
                if (
$pid) // parent
               
{
                   
$pid_arr[$i] = $pid;
                }
                else
// child
               
{
                   
performSomeFunction($i+1);
                }
            }
           
$i++;
        }

        while(
count($pid_arr) > 0)
        {
               
$myId = pcntl_waitpid(-1, $status, WNOHANG);
                foreach(
$pid_arr as $key => $pid)
                {
                        if(
$myId == $pid) unset($pid_arr[$key]);
                }
               
usleep(100);
        }

       
$elapsed = microtime(TRUE) - $starttime;
        print
"\n==> total elapsed: " . sprintf("%f secs.\n", $elapsed);
?>
saguto dot l7cc at gmail dot com 09-Apr-2008 09:09
please note, if you using configure option --enable-sigchild(Enable PHP's own SIGCHLD handler) when complie php(under linux 2.6.18-53.1.13.el5.centos.plus and php 5.2.5 as I know), pcntl_waitpid and pcntl_wait in php script would never return the child pid, because the build in handle get it first.
Kevin 10-May-2006 03:40
---
       while ($i < intval($argv[1]))
       {
           $pid = pcntl_fork();
           if ($pid == -1)
           {
               die('could not fork');
           }
           else
           {
               if ($pid) // parent
               {
                   $pid_arr[$i] = $pid;
               }
               else // child
               {
                   performSomeFunction($i+1);
               }
           }
           $i++;
       }
---

careful, this will create a lot more children than you probably expect. You must return or exit after performSomeFunction($i+1); ie,

               else // child
               {
                   performSomeFunction($i+1);
                   exit(0);
               }
admin at albert dot us dot com 06-Mar-2006 10:48
Here's a decent example of the pcntl_waitpid() call:

        $i = 0;
        $starttime = microtime(TRUE);
        $pid_arr = array();
        while ($i < intval($argv[1]))
        {
            $pid = pcntl_fork();
            if ($pid == -1)
            {
                die('could not fork');
            }
            else
            {
                if ($pid) // parent
                {
                    $pid_arr[$i] = $pid;
                }
                else // child
                {
                    performSomeFunction($i+1);
                }
            }
            $i++;
        }
        foreach ($pid_arr as $pid)
        {
            // we are the parent
            pcntl_waitpid($pid, $status);
        }
        $elapsed = microtime(TRUE) - $starttime;
        print "\n==> total elapsed: " . sprintf("%f secs.\n", $elapsed);

 
show source | credits | stats | sitemap | contact | advertising | mirror sites