let pdfork ?(nb=false) f = 
  let getchans() = cpipe ~nonblock:nb () in
  let srd, dwr = getchans() and drd, swr = getchans() in (* crossed pipes *)
  let close_dad ()= close_in drd; close_out dwr   in (* close the ends of the dad *)
  let close_son ()= close_in srd; close_out swr   in (* close the ends of the son *)
    match Unix.fork() with
      | 0 -> (if Unix.fork() <> 0 then () else begin close_dad(); f srd swr end); exit 0
      | n ->  ignore (Unix.waitpid [] n) ; close_son(); drd, dwr