The problem is that your buffers are filling up.
You keep on writing to your pipe, but you don't
read from it until all children have finished
writing. But eventually, the buffer fills up,
the child that's currently writing cannot write
and hence will block. In the main time,
your main program is waiting for the child to
exit.
So, you have a deadlock. You have a child that is
waiting for the parent to read something, and a parent
that's waiting for a child to terminate.
Abigail