open of a pipe and waitpid()

A

Andreas Boehm

Hello,

does there exist an interference between close() and waitpid() in the
folling code fragement, that uses an open() to a piped command?

$fhcmd=new FileHandle;
$pidcmd=open($fhcmd,"$cmd |");
if (defined($pidcmd)) {
$selcmd=new IO::Select($fhcmd);
while (!eof($fhcmd)) {
my (@cmdfhready);
@cmdfhready=$selcmd->can_read(1);
if (scalar(@cmdfhready)>0) {
$a=<$fhcmd>;
print STDOUT $a;
}
}
close $fhcmd;
waitpid $pidcmd, 0;
} else {
$fhcmd=undef;
$pidcmd=undef;
$OK=1;
}

Does there exist a need of a waitpid() after the close()?

regards,
Andreas
 
A

Anno Siegel

Andreas Boehm said:
Hello,

does there exist an interference between close() and waitpid() in the
folling code fragement, that uses an open() to a piped command?

$fhcmd=new FileHandle;
$pidcmd=open($fhcmd,"$cmd |");
if (defined($pidcmd)) {
$selcmd=new IO::Select($fhcmd);
while (!eof($fhcmd)) {
my (@cmdfhready);
@cmdfhready=$selcmd->can_read(1);
if (scalar(@cmdfhready)>0) {
$a=<$fhcmd>;
print STDOUT $a;
}
}
close $fhcmd;
waitpid $pidcmd, 0;
} else {
$fhcmd=undef;
$pidcmd=undef;
$OK=1;
}

Does there exist a need of a waitpid() after the close()?

No.

From "perldoc close":

set to 0.) Closing a pipe also waits for the
process executing on the pipe to complete, ...

The only way to "wait (for a process) to complete" under Unix is
wait() or watipid(), so close has already done that.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top