是否可以显示异步IO的进度
Is it possible to display progress of Asynchronous IO
我正尝试在 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 函数的进度?
你有不同的结果,因为每个不同的执行都有自己的执行上下文,可能与其他执行不同(你总是沿着完全相同的路径从你家到银行吗?即使是,经过的时间到达银行总是完全一样?最后是同样的任务——你在银行,不同的执行)。您的程序试图测量的不是 I/O 完成,而是它测试完成某些异步 I/O.
的次数
不,没有给定异步完成百分比的概念-I/O。
我正尝试在 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 函数的进度?
你有不同的结果,因为每个不同的执行都有自己的执行上下文,可能与其他执行不同(你总是沿着完全相同的路径从你家到银行吗?即使是,经过的时间到达银行总是完全一样?最后是同样的任务——你在银行,不同的执行)。您的程序试图测量的不是 I/O 完成,而是它测试完成某些异步 I/O.
的次数不,没有给定异步完成百分比的概念-I/O。