linux - 将负文件描述符传递给轮询

标签 linux operating-system polling systems-programming

轮询函数的手册页说:

   ...       
   int poll(struct pollfd *fds, nfds_t nfds, int timeout);
   ...

   struct pollfd {
               int   fd;         /* file descriptor */
               short events;     /* requested events */
               short revents;    /* returned events */
           };
   ...
   The field fd contains a file descriptor for an open file.  If this
   field is negative, then the corresponding events field is ignored and
   the revents field returns zero.  (This provides an easy way of
   ignoring a file descriptor for a single poll() call: simply negate
   the fd field.  Note, however, that this technique can't be used to
   ignore file descriptor 0.)

所以如果我定义pollfd结构如下:

   struct pollfd pollevent;
   pollevent.fd=-1;
   pollevent.event=POLLIN;

是不是说对于fd=1打开的文件,所有的POLLIN事件都会被忽略?

最佳答案

没有。只有带有负文件描述符的 struct pollfd 会被忽略。

关于linux - 将负文件描述符传递给轮询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45207194/

相关文章:

c - 共享内存和IPC

assembly - CPU 从用户模式切换到内核模式 : What exactly does it do? 它是如何进行这种转换的?

c - 非阻塞套接字连接的轮询中出现意外的 revents 值

java - 执行java程序时^M的原因

Linux命令: Find string in files content

linux - ccx - 微积分 : why occurs an error when I want to execute ccx?

linux - SO_REUSEADDR(setsockopt 选项)的含义是什么 - Linux?

java - 延迟队列延迟后轮询

java - AWS SQS : how do we consume message

linux - vi/vim 中如何对所有代码或一段代码进行自动代码对齐?