[LCP]Fork freezes when forking more then one

Steve Baker ice at mama.indstate.edu
Tue Aug 26 07:48:02 UTC 2003


juman <juman at chello.se> writes:
> I tested to rewrite the software as :
>
> Directly after forking in the parent I close as
> close (run->cp[OUTPUT]);
> close (run->pc[INPUT]);

  Okay, good.

> Before reading from child I close as
> close(run->pc[OUTPUT]);

  Why do you do that?  It isn't necessary, and if the program is wanting more
input for some reason, it will likely die at the point it tries to read more
data (broken pipe).

> And now in the main I can actually start 2 processes as
> int main(void)
> {
>     prog *a, *b;
>
>     a = runthis ("/root/mp3/musidab/src/test.awk");
>     b = runthis ("/root/mp3/musidab/src/test.awk");
>     write_to_child (b, "testa.mp3");
>     write_to_child (a, "testb.mp3");
>     stoprunning (b);
>     stoprunning (a);
>
>     return 0;
> }

  I'm curious as to what the test.awk script does, does it possibly need a
'\n' after the filename you give it, so perhaps you should be sending:

  write_to_child (b, "testa.mp3\n");

  instead, as stdin is normally line buffered?  It's possible I guess that
when you close the parent side writer that the child grabs what input it can
and processes it.  I'm just guessing, since I don't know how the awk script
works at all.

> But now it only works if I close the processes in the order b and then
> a. If I turn them around the software hangs again... (I have also fixed
> the error I had when using malloc) But I guess there is still something
> wrong or must there be any specific close order?

  I suspect that a child is blocked on some I/O, perhaps trying to read more
data from the parent.

								- Steve



More information about the linuxCprogramming mailing list