- waitpid PID,FLAGS
-
Waits for a particular child process to terminate and returns the pid of the deceased process, or
-1if there is no such child process. A non-blocking wait (with WNOHANG in FLAGS) can return 0 if there are child processes matching PID but none have terminated yet. The status is returned in$?and${^CHILD_ERROR_NATIVE}.特定の子プロセスが終了するのを待ち、消滅したプロセスの pid を 返します; 指定した子プロセスが存在しないときには、
-1を返します。 (FLAGS に WNOHANG を指定した) 非ブロッキング wait は、 PID がマッチングする子プロセスがいてもまだ終了していない場合に 0 を 返すことがあります。 ステータスは$?と${^CHILD_ERROR_NATIVE}に返されます。A PID of
0indicates to wait for any child process whose process group ID is equal to that of the current process. A PID of less than-1indicates to wait for any child process whose process group ID is equal to -PID. A PID of-1indicates to wait for any child process.PID に
0を指定すると、プロセスグループ ID が現在のプロセスと同じである 任意の子プロセスを wait します。 PID に-1以下を指定すると、プロセスグループ ID が -PID に等しい 任意の子プロセスを wait します。 PID に-1を指定すると任意の子プロセスを wait します。If you say
以下のようにするか
use POSIX ":sys_wait_h"; my $kid; do { $kid = waitpid(-1, WNOHANG); } while $kid > 0;or
または
1 while waitpid(-1, WNOHANG) > 0;then you can do a non-blocking wait for all pending zombie processes (see "WAIT" in POSIX). Non-blocking wait is available on machines supporting either the waitpid(2) or wait4(2) syscalls. However, waiting for a particular pid with FLAGS of
0is implemented everywhere. (Perl emulates the system call by remembering the status values of processes that have exited but have not been harvested by the Perl script yet.)とすると、ブロックが起こらないようにして、全ての待機中ゾンビプロセスを wait します ("WAIT" in POSIX を参照してください)。 ブロックなしの wait は、システムコール wait_pid(2) か、 システムコール wait4(2) をサポートしているマシンで利用可能です。 しかしながら、特定の pid を
0の FLAGS での wait はどこでも 実装されています。 (exit したプロセスのステータス値を覚えておいて、Perl がシステムコールを エミュレートしますが、Perl スクリプトには取り入れられていません。)Note that on some systems, a return value of
-1could mean that child processes are being automatically reaped. See perlipc for details, and for other examples.システムによっては、返り値が
-1の場合は子プロセスが自動的に 刈り取られたことを意味するかもしれないことに注意してください。 詳細やその他の例については perlipc を参照してください。Portability issues: "waitpid" in perlport.
移植性の問題: "waitpid" in perlport。