2011-04-09 23 views
3
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.cepoll_ctl:操作不允許錯誤 - c程序

但是當我試圖執行程序 'epoll的',我得到了錯誤信息

epoll_ctl:不允許操作。

我試圖將'doc'文件的模式更改爲0777,但它不起作用。

什麼問題?謝謝:)

回答

7

epoll_ctl(2)

EPERM The target file fd does not support epoll. 

我要去猜測doc是一個普通文件。常規文件是總是準備好read(2)write(2)操作,因此它對於常規文件上的epoll(7)select(2)沒有任何意義。

如果doc是一個管道或unix域套接字,在這裏留言(所以我知道要刪除我的帖子)並修改您的問題,以便其他人不會犯同樣的錯誤。 :)

+0

你是對的! Doc是常規文件。我是編程的新手,所以你的回答對我很有幫助。謝謝 :) – webnoon 2011-04-09 08:30:01

1

在這種情況下,您正在打開一個常規文件。 epoll(),select()poll()對常規文件沒有意義。

如果是管道或插座,然後:

$mkfifo doc 
相關問題