Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: open(KID, "-|") and wait()?

by robartes (Priest)
on Apr 10, 2003 at 14:00 UTC ( [id://249616]=note: print w/replies, xml ) Need Help??


in reply to Re: open(KID, "-|") and wait()?
in thread open(KID, "-|") and wait()?

how do I prevent the close() from blocking until the child exits?
You could delay the close until you know for sure the child process has finished. Use the non blocking version of waitpid for this. From the docs:
use POSIX ":sys_wait_h"; $kid = waitpid(-1, WNOHANG);
This will see if any child has died (without blocking) and return the PID of said child (and the return value in $?, as normal). You can also wait for a specific child by using the pid of that child as first argument to waitpid.

Using this, you can make sure you only close the filehandle when the child has already exited. Just periodically check whether the child is dead, and close its filehandle if it is (you'll get a -1 return from the close, but that should be no problem).

Unfortunately, this is not portable to all OS. See waitpid for more information.

Update: 'now' ne 'know'

CU
Robartes-

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://249616]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found