记录一个aio-nr
/ 系统调用号(通常已定义在 <sys/syscall.h>,但安全起见显式写出)// 调用 io_setup,第一个参数是请求的最大数量,第二个是上下文指针。// 手动定义 AIO 相关类型和常量。
root@nyx:~# cat /proc/sys/fs/aio-nr
0
///////////
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <errno.h>
#include <string.h>
// 手动定义 AIO 相关类型和常量
typedef struct io_context *io_context_t;
// 系统调用号(通常已定义在 <sys/syscall.h>,但安全起见显式写出)
#ifndef __NR_io_setup
#define __NR_io_setup 0
#endif
#ifndef __NR_io_destroy
#define __NR_io_destroy 1
#endif
int main() {
io_context_t ctx = 0;
long ret;
// 调用 io_setup,第一个参数是请求的最大数量,第二个是上下文指针
ret = syscall(__NR_io_setup, 128, &ctx);
if (ret < 0) {
printf("io_setup failed: %s\n", strerror(errno));
return 1;
}
printf("AIO context created. ctx = %p\n", ctx);
printf("Now check: cat /proc/sys/fs/aio-nr\n");
printf("Press Enter to destroy context and exit...");
getchar();
syscall(__NR_io_destroy, ctx);
printf("Context destroyed.\n");
return 0;
}
////////////
gcc
./a.out
root@nyx:~# cat /proc/sys/fs/aio-nr
256
更多推荐



所有评论(0)