A variation on this is to write the whole thing in a
select loop, which waits for the filehandle from the parent to become readable and any other conditions. The parent filehandle will become readable as soon as it exits, and a read will return an end-of-file indicator.