I/O between parent and child processes

Joel Coltoff coltoff at burdvax.UUCP
Tue Feb 18 02:16:51 AEST 1986


I have a program that sets up pipes, forks and execs two children. The
parent then lets the user talk to either child or passes messages
between the two children. My question is is there a reliable way to
tell when one child's output is done other than the ugly method of
having it print "DONE" and making the parent look at every string the
children print. I suspect I need to use asynchronous I/O. The output
from the children isn't really asynch in nature. The children are
interactive programs that accept input, do all their calcualtions, and
then spit out thier answers. The code fragment below seems to be
working but I am worried about how it will behave when the load gets up
there? Will the code work the same if I replace the first while with
an if? My suspicions say that the last ( second ) call to select is
redundant but I put it there to be safe. I am sure that if I set the
timeout for select high enough I'll always get all the data but end up
wasting lots of time under many circumstances. Any insights you could
offer would be greatly appreciated.

---------
        ioctl( fileno(f1), FIONBIO, &on ); /* so that fgets() doesn't block */
        tv.tv_sec = 2;
        tv.tv_usec = 0;
        readfs = 1 << fileno(f1);
        while (select(fileno(f1) + 1, &readfs,0,0,&tv) > 0 ){
                while ( fgets( inbuf, 100, f1 ) != NULL ) {
                        wclrtoeol(wp);
                        wprintw(wp,"%s", inbuf );
                        wrefresh(wp);
                }
        }
        ioctl( fileno(f1), FIONBIO, &off );

---------
Thanks in advance,

        readfs = 1 << UUCP;
        select( 20, &readfs, 0, 0, (struct timeval *) 0 );

        Joel Coltoff
        {psuvax1,sdcrdcf}!burdvax!coltoff



More information about the Comp.unix.wizards mailing list