c语言epoll_ctl参数,epoll_ctl:不允许操作错误 – c程序

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`epoll_ctl` 函数用于向 epoll 实例中添加、修改或删除感兴趣的事件,其函数原型如下: ```c int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); ``` 其中,参数含义如下: - `epfd`:epoll 实例的文件描述符,即 `epoll_create` 函数返回的文件描述符。 - `op`:要进行的操作类型,可以是以下三种操作之一: - `EPOLL_CTL_ADD`:向 epoll 实例中添加感兴趣的事件。 - `EPOLL_CTL_MOD`:修改已添加的事件的属性。 - `EPOLL_CTL_DEL`:删除已添加的事件。 - `fd`:需要添加、修改或删除事件的文件描述符。 - `event`:指向 `epoll_event` 结构体的指针,用于表示感兴趣的事件。 `epoll_event` 结构体定义如下: ```c struct epoll_event { __uint32_t events; // 表示感兴趣的事件 epoll_data_t data; // 用户数据 }; typedef union epoll_data { void *ptr; int fd; __uint32_t u32; __uint64_t u64; } epoll_data_t; ``` 其中,`events` 可以是以下事件的组合: - `EPOLLIN`:表示对应的文件描述符可读。 - `EPOLLOUT`:表示对应的文件描述符可写。 - `EPOLLRDHUP`:表示对端关闭连接或者半关闭连接。 - `EPOLLPRI`:表示对应的文件描述符有紧急数据可读。 - `EPOLLERR`:表示对应的文件描述符发生错误。 - `EPOLLHUP`:表示对应的文件描述符被挂起。 - `EPOLLET`:表示事件采用边缘触发模式。 - `EPOLLONESHOT`:表示事件采用一次性触发模式。 `data` 字段可以存储用户数据,它的具体含义可以由用户自定义。在事件触发时,`data` 字段会被原封不动地返回给用户。在 `epoll_ctl` 函数中,`data` 字段通常会被用于存储文件描述符或其他与事件相关的信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值