From owner-freebsd-chat Thu Jun 13 23:36:26 1996 Return-Path: owner-chat Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id XAA11453 for chat-outgoing; Thu, 13 Jun 1996 23:36:26 -0700 (PDT) Received: from obie.softweyr.com (slc42.xmission.com [204.228.136.42]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id XAA11447 for ; Thu, 13 Jun 1996 23:36:22 -0700 (PDT) Received: (from wes@localhost) by obie.softweyr.com (8.7.5/8.6.12) id AAA00433; Fri, 14 Jun 1996 00:35:28 -0600 (MDT) Date: Fri, 14 Jun 1996 00:35:28 -0600 (MDT) Message-Id: <199606140635.AAA00433@obie.softweyr.com> From: wes@intele.net To: jsigmon@www.hsc.wvu.edu CC: chat@freebsd.org Subject: Re: Any alternatives for kbhit() and getch In-Reply-To: <199606132128.XAA15302@uriah.heep.sax.de> References: <31BF97BC.5E2D@access.mountain.net> <199606132128.XAA15302@uriah.heep.sax.de> Sender: owner-chat@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Jeremy Sigmon asked: % I am writing a timed program. I need to be checking the % time while waiting for input. This is to be written as much as % possible in ANSI C. Joerg Wunsch cleverly replied: > It's impossible in ANSI C (kbhit() ain't ANSI either). > > For the Unix environment, use select(2). It also handles the timing > for you. You might need to turn the terminal into ``raw'' mode as > well, otherwise all input processing will be handled in terms of lines. > RTFM termios(7) for this. You will most certainly need to put the terminal into raw mode; see cfmakeraw(3) while you're spelunking in the man pages. If you want to do reads that may be "timed out", select(2) is ideal. If you want to time the execution of your program, you may use the time(1) command, or simply call gettimeofday at the beginning and end of your program and print the difference. -- Wes Peters | Yes I am a pirate, two hundred years too late Softweyr | The cannons don't thunder, there's nothing to plunder Consulting | I'm an over forty victim of fate... softweyr@xmission.com | Jimmy Buffett