1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8
9 int main() {
10 struct epoll_event event ;
11 int ret,fd, epfd ;
12
13 fd = open("doc", O_RDONLY);
14 if( fd < 0 )
15 perror("open");
16
17 event.data.fd = fd ;
18 event.events = EPOLLIN|EPOLLOUT ;
19
20 epfd = epoll_create(50);
21 printf("%d", epfd );
22
23 if( epfd < 0 )
24 perror("epoll_create");
25
26 ret = epoll_ctl( epfd, EPOLL_CTL_ADD, fd, &event ) ;
27 if( ret < 0 )
28 perror("epoll_ctl");
29
30 }
编译此代码时,没有错误.
gcc -o epoll epoo.c
但是当我试图执行程序’epoll’时,我收到了错误消息
epoll_ctl:Operation not permitted.
我试图将’doc’文件的模式更改为0777,但它不起作用.
问题是什么?谢谢 :)
解决方法:
来自epoll_ctl(2):
EPERM The target file fd does not support epoll.
我猜这个doc是一个常规文件.常规文件随时可用于read(2)或write(2)操作,因此对常规文件中的epoll(7)或select(2)没有意义.
如果doc是管道或unix域套接字,请在这里发表评论(所以我知道删除我的帖子)并修改你的问题,以便其他人不会犯同样的错误.
标签:c-3,epoll,linux,file,io
来源: https://codeday.me/bug/20190726/1543433.html