概述
在/proc/pid/fdinfo里有关于进程打开文件的一些权限&位置信息,按照manpage是这样描述的:
/proc/[pid]/fdinfo/ (since kernel 2.6.22)
This is a subdirectory containing one entry for each file which the process has open, named by its file descriptor. The
contents of each file can be read to obtain information about the corresponding file descriptor, for example:
$ cat /proc/12015/fdinfo/4
pos: 1000
flags: 01002002
The pos field is a decimal number showing the current file offset. The flags field is an octal number that displays the
file access mode and file status flags (see open(2)).
The files in this directory are readable only by the owner of the process.
就是说pos:表明当前该进程对该文件的读写位置;flags是open文件时的权限,比如O_RDWR|O_TRUNC等等。下面举栗说明:
1)某未知进程打开一个log文件
[root@xx /proc/108490/fdinfo]#ls -l ../fd
total 0
...
l-wx------ 1 xx xx 64 Aug 9 21:39 5 -> /data1/home/xx/workspace/trunk/bin/log/lobby.log
2)查看fd==5
pos: 4114656
flags: 0100001
根据说明,pos是当前读写位置,一般写日志文件肯定都是写到文件尾的,所以目测这个pos可以代表文件的大小,验证一下
File: '/data1/home/xx/workspace/trunk/bin/log/lobby.log'
Size: 4114656 Blocks: 8048 IO Block: 4096 regular file
Device: 804h/2052d Inode: 6448732095 Links: 1
Access: (0666/-rw-rw-rw-) Uid: (30020/ xx) Gid: (30020/ xx)
Access: 2018-08-09 21:08:35.375586664 +0800
Modify: 2018-09-10 20:37:35.277841439 +0800
Change: 2018-09-10 20:37:35.277841439 +0800
确实文件size与pos一致。
3)下面对比flag,0100001
#define O_RDONLY 00
#define O_WRONLY 01
#define O_RDWR 02
#define O_CREAT 0100 /* not fcntl */
#define O_EXCL 0200 /* not fcntl */
#define O_NOCTTY 0400 /* not fcntl */
#define O_TRUNC 01000 /* not fcntl */
#define O_APPEND 02000
#define O_NONBLOCK 04000
#define O_NDELAY O_NONBLOCK
#define O_SYNC 010000
#define FASYNC 020000 /* fcntl, for BSD compatibility */
#define O_DIRECT 040000 /* direct disk access hint */
#define O_LARGEFILE 0100000
#define O_DIRECTORY 0200000 /* must be a directory */
#define O_NOFOLLOW 0400000 /* don't follow links */
#define O_NOATIME 01000000
比较一下,说明是open("xxxxx" , O_LARGEFILE|O_WRONLY);这样子打开的--
比如,另外打开一个文件O_WRONLY|O_APPEND|O_SYNC|O_NONBLOCK
然后查看对应的flags:
04116001
一般在64位下会默认加上O_LARGEFILE 所以实际上是
O_LARGEFILE|O_WRONLY|O_APPEND|O_SYNC|O_NONBLOCK=116001
最上面的04不知道是怎么搞上去的,这个仿佛适合O_SYNC标记有关,此处存疑。
最后
以上就是无限酒窝为你收集整理的fdinfo 的说明的全部内容,希望文章能够帮你解决fdinfo 的说明所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复