Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: $Revision: 1.6.2.14 $; site umn-cs.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!stolaf!umn-cs!bolte From: bolte@umn-cs.UUCP Newsgroups: net.unix-wizards Subject: Re: Need Non-Blocking Terminal Input Fun Message-ID: <800002@umn-cs.UUCP> Date: Sat, 25-Jan-86 22:38:00 EST Article-I.D.: umn-cs.800002 Posted: Sat Jan 25 22:38:00 1986 Date-Received: Tue, 28-Jan-86 05:22:13 EST References: <482@kontron.UUCP> Lines: 44 Nf-ID: #R:kontron:-48200:umn-cs:800002:000:1196 Nf-From: umn-cs!bolte Jan 25 21:38:00 1986 There is a very simple way to do what you want. The select (2) call can be used to wait for input from a file descriptor or return after a certain amount of time. Here is a complete program to do just that. Note: it is for BSD 4.2 Scott Bolte U. of Minnesota A.I. Lab ihnp4!umn-cs!bolte ================================================================================ #include #include #include main(argc,argv) char *argv[]; { int ifd,flag; struct timeval tim; tim.tv_sec = (argc>1)?atoi(argv[1]):3; /* wait for argv[1] seconds */ /* default is 9 */ tim.tv_usec = 0; ifd = 1<<0; /* Since stdin is file descriptor 0 only shift by zero. To wait for file descriptor x as well add the line 'ifd |= 1<