Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

advise me please, which is better or tell other ways
$p = open P, 'xxx|' 1) while (sysread P) {...}; close P; wait(); 2) while (1) {...if($p==waitpid($p,WNOHANG)){last}}; close P;
My os is Debian. Both works but which is more correct

Replies are listed 'Best First'.
Re: how to determine pipe process terminated or alive
by Zaxo (Archbishop) on Jun 16, 2007 at 15:22 UTC

    Sometimes

    sleep $interval while kill 0, $pid;
    is handy. It works for any process you have rights to signal, not just kids or parent.

    After Compline,
    Zaxo

Re: how to determine pipe process terminated or alive
by kyle (Abbot) on Jun 18, 2007 at 02:57 UTC

    Regarding your first example, when you close a pipe, a wait is done also, so your explicit wait is not necessary.