Linux Terminal Problem with Non-Canonical Terminal I/O app -


I have a small app written in C to run on Linux. Part of the app accepts user-input from keyboard , And it uses non-canonical terminal mode so that it can respond to each keystroke.

The section of the code that accepts input is a simple task that is called repeatedly in the loop:

  char get_input () {char C = 0; Int res = reading (input_tamille, & amp; c, 1); If (RSS == 0) 0 returns; If (res == -1) {/ * snip error handling * /} return c; }  

It reads a letter from the terminal if there is no input within a given time limit, (c_cc [VTIME] value in the vocabulary structure), read () 0 And get_input () is called again

It all works very well, I have recently discovered that if you run this app in a terminal window, and then the app Close the terminal window without ending, the app will not exit Received, but CPU intensive launches into an infinite loop, where the read () returns 0 without waiting continued.

So how can I get out of the apple if it runs from the terminal window, and then closes the terminal window? The problem is that read (1) never returns -1, so the state of error is not different from a normal position, where the read (0) returns. So the only solution I see is to put it in the timer, and assume that there is an error condition, read the return 0 faster from the time specified in C_cc [V_TIME] but this solution looks best, and I was hoping that this There is a better way to handle the situation.

Any thoughts or suggestions?

Do you keep holding the keys before resetting your programs and resetting them? I think SIGHUP is the one you need to focus on. Probably set a switch in the signal handler, if the switch () is switched on and switches out while clearing.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -