LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2031|回复: 1

How select() works(select()的实现机制)

[复制链接]
发表于 2004-1-28 22:59:33 | 显示全部楼层 |阅读模式
How select() works


  1. A file descriptor is associated with a file structure.
  2. In the file structure, there is a set of operations supported by this file type called file_operations.
  3. In the file_operations structure, there is an entry named poll.
  4. What the generic select() call does is call this poll() function to get status of a file (or socket or whatever) as the name suggests.

  5. In general, the select() works like

  6.     while(1)

  7.     {

  8.          for each file descriptor in the set

  9.          {

  10.              call file's poll() to get mask.

  11.              if(mask & can_read or mask & can_write or mask & exception)

  12.              {

  13.                  set bit for this fd that this file is readable/writable or there is an
  14.                  exception.

  15.                  retval++;

  16.              }

  17.          }

  18.          if(retval != 0)

  19.              break;

  20.          schedule_timeout(__timeout);

  21.     }

  22. For detailed implementation of select(), please take a look at sys_select() and do_select() in fs/select.c. of standard kernel source code.

  23. Another thing required to understand is poll_wait(). What it does is put current process into a wait
  24. queue provided by each kernel facilities such as file or pipe or socket or in our case, message queue.

  25. Please note that the current process may wait on several wait queues by calling select()
复制代码
发表于 2004-1-29 10:33:40 | 显示全部楼层
呵呵,有意思,看来有机会看看linux的kernel源代码还是很有必要的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表