【发布时间】:2016-01-16 19:17:19
【问题描述】:
这是最小的例子(故意忽略错误检查和信号安全):
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/eventfd.h>
#include <stdio.h>
#include <sys/wait.h>
void reader(int a)
{
printf("hello!\n");
wait(NULL);
exit(EXIT_SUCCESS);
}
int main()
{
signal(SIGIO, reader);
int efd = eventfd(0, EFD_NONBLOCK);
fcntl(efd, F_SETOWN, getpid());
int flags;
flags= fcntl(efd, F_GETFL);
fcntl(efd, F_SETFL, flags | O_ASYNC);
pid_t p = fork();
if (p)
{
for(;;)
pause();
}
else
{
uint64_t buff = 1;
if (write(efd, &buff, sizeof(buff)) == -1)
printf("write error\n");
exit(EXIT_SUCCESS);
}
}
在子进程写入事件文件描述符后,这段代码应该在父进程中生成 SIGIO,但它没有。我什至尝试从 eventfd 系统调用中删除 EFD_NONBLOCK 并且我有相同的行为。所以这里有几个问题。
这是处理中断驱动的 I/O 的正确方法吗?
中断驱动的 I/O 能否与事件文件描述符结合使用?如何使用?
【问题讨论】:
标签: c linux io system-calls