Io 如何判断O_DIRECT是否正在使用?
我正在运行一个支持O_DIRECT的IO密集型进程。在进程运行时,有没有办法判断是否正在使用O_DIRECT 我尝试了“Io 如何判断O_DIRECT是否正在使用?,io,linux-kernel,Io,Linux Kernel,我正在运行一个支持O_DIRECT的IO密集型进程。在进程运行时,有没有办法判断是否正在使用O_DIRECT 我尝试了“iostat-x1”,但我不确定哪个字段对我有帮助 谢谢。您必须获得正在运行的进程的pid。一旦你得到pid,你就可以 cat /proc/[pid]/fdinfo/<fd number> 然后用O_DIRECT打开foo1,不使用O_DIRECT打开foo2。下面是节目 #define _GNU_SOURCE #include <stdio.h> #
iostat-x1
”,但我不确定哪个字段对我有帮助
谢谢。您必须获得正在运行的进程的pid。一旦你得到pid,你就可以
cat /proc/[pid]/fdinfo/<fd number>
然后用O_DIRECT
打开foo1,不使用O_DIRECT
打开foo2。下面是节目
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main()
{
printf("%u\n", getpid());
int fd1 = open("foo1", O_RDWR|O_DIRECT); //O_DIRECT set
printf("foo1: %d\n", fd1);
int fd2 = open("foo2", O_RDWR); //Normal
printf("foo2: %d\n", fd2);
sleep(60);
close(fd1);
close(fd2);
return 0;
}
从上面的输出中,您可以看到,对于
O_DIRECT
,在标志字段中也设置了0040000
。您在寻找什么意思?当IO正在进行时?文件何时打开?IO完成时。
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main()
{
printf("%u\n", getpid());
int fd1 = open("foo1", O_RDWR|O_DIRECT); //O_DIRECT set
printf("foo1: %d\n", fd1);
int fd2 = open("foo2", O_RDWR); //Normal
printf("foo2: %d\n", fd2);
sleep(60);
close(fd1);
close(fd2);
return 0;
}
8885
foo1: 3 //O_DIRECT
foo2: 4
8885 is the pid. So I did
cat /proc/8885/fdinfo/3 //O_DIRECT
pos: 0
flags: 0140002
mnt_id: 29
-------------------------------
cat /proc/8885/fdinfo/4
pos: 0
flags: 0100002
mnt_id: 29