简体   繁体   English

在Linux驱动程序中轮询系统调用

[英]poll system call in linux drivers

I am learning Linux internals. 我正在学习Linux内部知识。 So I came across the poll system call. 所以我遇到了poll系统调用。 As far as I understand, it is used by drivers to provide notification when some data is ready to be read from device and when we have data ready to device. 据我了解,当某些数据准备从设备中读取以及当我们有数据准备就绪时,驱动程序会使用它来提供通知。

If device do not have any data to read, process will get sleep and wake up when data become available and vice versa for write case. 如果设备没有任何要读取的数据,则在数据可用时进程将进入睡眠状态并唤醒,反之亦然。

Can someone provide me concrete understanding of poll system call with some real example? 有人可以通过一些真实的例子为我提供对轮询系统调用的具体理解吗?

poll and select (the latter is very similar to poll with these differences) sys calls are used in so called asynchronous event-driven approach for handling client's requests. 轮询和选择(后者与轮询非常相似,但有这些区别)在所谓的异步事件驱动方法中使用sys调用来处理客户端的请求。

Basically, in network programming there are two major strategies for handling many connections from network clients by the server: 基本上,在网络编程中,有两种主要策略可以处理服务器与网络客户端的许多连接:

1) more traditional: threaded or process-oriented approach. 1)更传统:线程或面向过程的方法。 In this situation network server has main proccess which listens on one specific network port (port 80 in case of web servers) for incomming connections and when connection arrives, it spawns new thread/process to handle this new connection. 在这种情况下,网络服务器具有主进程,该进程侦听一个特定的网络端口(对于Web服务器,为端口80)来输入连接,当连接到达时,它会产生新的线程/进程来处理此新连接。 Apache HTTP server took this approch. Apache HTTP服务器采用了这一方法。

2) aforementioned asynchronous event-driven approach where (in simplest case) network server (for example web server) is application with only one process and it accepts connections (creating socket for each new client) and then it monitors those sockets with poll/select for incoming data. 2)前述异步事件驱动方法,其中(在最简单的情况下)网络服务器(例如Web服务器)是仅具有一个进程的应用程序,并且它接受连接(为每个新客户端创建套接字),然后通过轮询/选择监视这些套接字用于输入数据。 Nginx http web server took this approch. Nginx http Web服务器采用了此方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM