select-syscall

Why is select used in Linux

亡梦爱人 提交于 2019-11-28 18:12:05
I was going through a serial program and I observed that they use select() before using read() . Why exactly is this required. Why cant we just directly call read() and check if it fails or not ? Also why do we have to increment the file descriptor by 1 and pass it while I am passing the file descriptor set already to select() ? Example: r=select(fd+1, &fds, NULL, NULL, &timeout); where fds already has the value of fd The select() system call tells you whether there is any data to read on the file descriptors that you're interested in. Strictly, it is a question of whether a read operation on

Why is select used in Linux

瘦欲@ 提交于 2019-11-27 20:16:26
问题 I was going through a serial program and I observed that they use select() before using read() . Why exactly is this required. Why cant we just directly call read() and check if it fails or not ? Also why do we have to increment the file descriptor by 1 and pass it while I am passing the file descriptor set already to select() ? Example: r=select(fd+1, &fds, NULL, NULL, &timeout); where fds already has the value of fd 回答1: The select() system call tells you whether there is any data to read