epoll_ctl:操作不允许错误 - C 程序
1 #include <sys/epoll.h>
2 #include <stdio.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <string.h>
7 #include <sys/uio.h>
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:不允许操作。
我尝试将“doc”文件的模式更改为 0777,但没有成功。
问题是什么?谢谢 :)
1 #include <sys/epoll.h>
2 #include <stdio.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <string.h>
7 #include <sys/uio.h>
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 }
When compiling this code, there was no errors.
gcc -o epoll epoo.c
but when i tried to execute the program 'epoll', i got the error message
epoll_ctl:Operation not permitted.
I've tried to change the 'doc' file's mode to 0777 but it was not work.
What is the problem? Thank you :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自
epoll_ctl(2)
:我猜测
doc
是一个常规文件。常规文件总是准备好进行read(2)
或write(2)
操作,因此对epoll没有意义(7)
或select(2)
在常规文件上。如果 doc 是管道或 unix 域套接字,请在此处发表评论(这样我就知道删除我的帖子)并修改您的问题,以便其他人不会犯与我相同的错误。 :)
From
epoll_ctl(2)
:I'm going to guess that
doc
is a regular file. Regular files are always ready forread(2)
orwrite(2)
operations, thus it doesn't make sense toepoll(7)
orselect(2)
on regular files.If
doc
is a pipe or unix domain socket, comment here (so I know to delete my post) and amend your question so others don't make the same mistake I did. :)在这种情况下,您将打开一个常规文件。
epoll()
、select()
和poll()
对常规文件没有意义。如果它是管道或插座,则:
In this case you're opening a regular file.
epoll()
,select()
, andpoll()
don't make sense on regular files.If it is a pipe or socket, then: