How can I read keyboard without stopping

Benjamin G. Golding bgg at yarra.oz.au
Wed Aug 17 11:32:33 AEST 1988


In article <1246 at mcgill-vision.UUCP>, mouse at mcgill-vision.UUCP (der Mouse) writes:
> In article <813 at ms3.UUCP>, isns02 at ms3.UUCP (Harris Reavin) writes:
> > I would like to know if it is possible to get input data from the
> > keyboard while my program is constantly looping and displaying output
> > to the screen.  The input comes from a call to "popen()".
>
> [der mouse lists four techniques to do this]

 5) A pair of processes and a pipe.  Have the main process create a
    pipe and spawn a subprocess to do all the work; it can then block
    reading from the keyboard.  When keyboard input arrives, the main
    process copies it to the pipe for the other process and sends a
    signal to notify it that data is waiting there.

    Good: It will work almost anywhere, even V6!  It is simple and
    natural: there are two tasks to be done, so we have two processes.

    Bad: If we lose a signal we may not get all input as it arrives.
    This may be acceptable because people can't type very fast at the
    keyboard.  The sensible thing to do would be to check the amount of
    data in the pipe using stat() before reading it.  This doesn't work
    under Berkeley unix because it sets st_size to 0 on a pipe - a
    peculiar thing to do.

	Ben.



More information about the Comp.unix.wizards mailing list