, , ,
"select()", ( , Posix) os.
'select()' 3 , (. man select, FD_SET ..). , , ( )
man:
'select()' " , , " " - (, ). , - (, (2) ...)"
select:
a) fd, , fd , - (, , , ), select ... ", " " - , fd, .
( select) fd ( ). , 1 - , . 1 fd (.. ), 1 , . select "" (, , char).
b) , , fd. fd , , "select()" 0. (.. ). - , , .
fyi - fd 0,1,2... , C 0 STDIN, 1 STDOUT.
Easy test setup: I open a terminal (separate from my console) and type the tty command on that terminal to find my identifier. The answer is usually similar to "/ dev / pts / 0" or 3 or 17 ...
Then I get fd for use in 'select ()' using open:
int inFD = open( "/dev/pts/5", O_RDONLY );
It is useful to disable this value.
Here is a snippet to consider (from a person):
fd_set rfds;
struct timeval tv;
int retval;
FD_ZERO(&rfds);
FD_SET(0, &rfds);
tv.tv_sec = 5;
tv.tv_usec = 0;
retval = select(1, &rfds, NULL, NULL, &tv);
if (retval == -1)
perror("select()");
else if (retval)
printf("Data is available now.\n");
else
printf("No data within five seconds.\n");