Why is select used in Linux

前端 未结 3 1101
星月不相逢
星月不相逢 2020-12-13 12:46

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 dire

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 13:09

    Programs that want to continue running while also reading interactive user input1 need to be multithreaded or they need to read input streams carefully and, specifically, conditionally.

    Select(2) can be used to implement the second design pattern. It can determine whether input can be read without blocking the entire application.


    1. Or some other input that arrives unpredictably.

提交回复
热议问题