我正在尝试在linux中使用POSIX异步IO API实现文件复制程序。
我试过这个:
main() {
char data[200];
int fd = open("data.txt", O_RDONLY); // text file on the disk
struct aiocb aio;
aio.aio_fildes = fd;
aio.aio_buf = data;
aio.aio_nbytes = sizeof(data);
aio.aio_offset = 0;
memset(&aio, 0, sizeof(struct aiocb));
aio_read(arg->aio_p);
int counter = 0;
while (aio_error(arg->aio_p) == EINPROGRESS) {
printf("counter: %d\n", counter++);
}
int ret = aio_return(&aio);
printf("ret value %d \n",ret);
return 0;
}但是每次我运行时计数器都会给出不同的结果
是否可以显示aio_read和aio_write函数的进度?
发布于 2017-12-14 19:52:29
你会得到不同的结果,因为每个不同的执行都有自己不同的执行上下文(你总是沿着完全相同的路径从你的房子到银行吗?即使是这样,到达银行所用的时间总是完全一样的吗?最后是同样的任务--你在银行,不同的执行)。您的程序尝试测量的不是I/O完成,而是它测试某些异步I/O完成的时间。
不,不存在给定异步I/O的完成百分比的概念。
https://stackoverflow.com/questions/47779943
复制相似问题