ImportC and color syntax highlighting

Walter Bright newshound2 at digitalmars.com
Sun Sep 12 09:32:38 UTC 2021


On 9/12/2021 2:23 AM, Walter Bright wrote:
> On 9/11/2021 4:04 PM, jfondren wrote:
>> When running it, it pegs a CPU at 100% because it's constantly running 
>> ttkeysininput(). That's enough to cause a fan to run at high speed on this 
>> laptop. But, that's easily fixed with select() or similar against stdin.
> 
> I'm not too familiar with I/O on Linux. If you could modify ttkeysininput() to 
> use select(), I'm interested to learn how it's done. Thanks!

I'm looking at:

  #include <stdio.h>
  #include <sys/select.h>

  int main(void) {
     fd_set s_rd, s_wr, s_ex;
     FD_ZERO(&s_rd);
     FD_ZERO(&s_wr);
     FD_ZERO(&s_ex);
     FD_SET(fileno(stdin), &s_rd);
     select(fileno(stdin)+1, &s_rd, &s_wr, &s_ex, NULL);
     return 0;
  }

from

 
https://stackoverflow.com/questions/6418232/how-to-use-select-to-read-input-from-keyboard-in-c

Comparing it with the man page makes sense.

   https://man7.org/linux/man-pages/man2/select.2.html

I'll give it a try.


More information about the Digitalmars-d mailing list