Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!rpi!zaphod.mps.ohio-state.edu!samsung!munnari.oz.au!csource!david From: david@csource.oz.au (david nugent) Newsgroups: comp.lang.c Subject: Re: unix c help Keywords: unix c communications kbhit Message-ID: <561@csource.oz.au> Date: 10 Jul 90 17:51:20 GMT References: <1950@novavax.UUCP> Organization: Unique Computing Pty Ltd, Melb, Aust. Lines: 33 In <1950@novavax.UUCP> raab@novavax.UUCP (Moshe Raab) writes: >i have been coding in c for a number of years. all of this >time i have been programming using MSC, using the MS extensions. >recently, i installed Mark Williams Coherent (unix like) >operating system. i started writing my own simple communications >program but have hit some unexpected snags. for example, how does >one monitor the keyboard and the com port at the same time. >in MSC i use, kbhit(). i could theoretically write my own >kbhit in assemlby using the bios call to interrup 0x16 but >that would make it unportable. if any one has any suggestions, >please let me know. The whole approach of polling for input should be completely scrapped. With Unix, you have _much_ better resource usage than sitting in an idle loop wasting machine cycles. Basically, to do this type of thing there are a number of different angles. The easiest is to use multiple processes, each to wait on the activity you're monitoring - and effectively 'sleep' while nothing is happening. The Unix 'cu' utility is a good example; it uses fork() to generate a child process to accept input from the port, and echo it to the screen via stdout. The parent process accepts keyboard input and passes it out the port. -- _______________________________________________________________________________ Unique Computing Pty Ltd Melbourne Australia - Communications Specialists david@csource.oz.au 3:632/348@fidonet 28:4100/1@signet