perl-5.38.0
waitpid PID,FLAGS

Waits for a particular child process to terminate and returns the pid of the deceased process, or -1 if 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 0 indicates to wait for any child process whose process group ID is equal to that of the current process. A PID of less than -1 indicates to wait for any child process whose process group ID is equal to -PID. A PID of -1 indicates 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 0 is 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 -1 could 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