Path: utzoo!utgpu!attcan!uunet!munnari!ditmela!yarra!bgg
From: bgg@yarra.oz.au (Benjamin G. Golding)
Newsgroups: comp.unix.wizards
Subject: Re: How can I read keyboard without stopping
Summary: a general solution
Keywords: curses keyboard
Message-ID: <51@yarra.oz.au>
Date: 17 Aug 88 01:32:33 GMT
References: <813@ms3.UUCP> <1246@mcgill-vision.UUCP>
Organization: Pyramid Technology Corp. (Australia)
Lines: 25

In article <1246@mcgill-vision.UUCP>, mouse@mcgill-vision.UUCP (der Mouse) writes:
> In article <813@ms3.UUCP>, isns02@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.