I have a small application written in C designed to work on Linux. Part of the application accepts user input from the keyboard and uses the non-canonical mode of the terminal so that it can respond to every keystroke.
The section of code that receives the input is a simple function that is called multiple times in a loop:
char get_input()
{
char c = 0;
int res = read(input_terminal, &c, 1);
if (res == 0) return 0;
if (res == -1) { }
return c;
}
This reads one character from the terminal. If the input is not received within a certain timeframe (indicated by c_cc [VTIME] in the termios struct), read () returns 0, and get_input () is called again.
All this works fine, except that I recently discovered that if you run this application in the terminal window, and then close the terminal window without stopping the application, the application will not exit, but starts in an intensive cycle with heavy processor use, where read () continuously returns 0 without waiting.
, , , ? , read() -1, , read() 0. , , , - , , read 0 , , c_cc [V_TIME]. , , .
?
Charles Salvia