linux文件描述符open file descriptors与open files的区别

原文链接

什么是open file

An open file may be a regular file, a directory, a block special file, a character special file, an executing text reference, a library, a stream or a network file.

 

什么是file descriptor

A file descriptor is a data structure used by a program to get a handle on a file. The most commonly known are:

0 for standard in

1 for standard out

2 for standard error

 

两者关系

一个文件即使被打开,也可能没有文件描述符,比如current working directories, memory mapped files and executable text files

lsof可以查出某个进程打开的文件数目,

[root@testbox ~]# lsof | grep '4448' (4448为pid)

oracle   4448 oracle cwd      DIR       3,2     4096   1913941 /u01/app/oracle/product/10.2.0/db_1/dbs

oracle   4448 oracle rtd      DIR       3,2     4096         2 /

oracle   4448 oracle txt      REG       3,2 93300099   1915187 /u01/app/oracle/product/10.2.0/db_1/bin/oracle

oracle   4448 oracle mem      REG       3,2    95148   2174926 /lib/libnsl-2.3.4.so

oracle   4448 oracle mem      REG       3,2   106397   2174894 /lib/ld-2.3.4.so

oracle   4448 oracle mem      REG       3,2  1454546   2501884 /lib/tls/libc-2.3.4.so

:

[root@testbox ~]# lsof | grep '4448' | wc -l

42

以下方法用于查询进程使用的文件描述符数目

[root@testbox ~]# ls -l /proc/4448/fd/

total 18

lr-x------ 1 oracle oinstall 64 Mar 5 15:04 0 -> /dev/null

lr-x------ 1 oracle oinstall 64 Mar 5 15:04 1 -> /dev/null

lrwx------ 1 oracle oinstall 64 Mar 5 15:04 10 -> /u01/app/oracle/product/10.2.0/db_1/rdbms/audit/ora_4446.aud

lr-x------ 1 oracle oinstall 64 Mar 5 15:04 11 -> /dev/zero

lr-x------ 1 oracle oinstall 64 Mar 5 15:04 12 -> /dev/zero

:

[root@testbox ~]# ls -l /proc/4448/fd/ | wc -l

19

进程4448总共打开42个文件,只占用了19个文件描述符;

 

查看文件描述符的设置

$cat /proc/sys/fs/file-max

65536

--该参数可以动态修改

 

计算当前被使用的文件描述符数目

$cat /proc/sys/fs/file-nr

1380 180 65536

  | |  |_ Max no. of file descriptors allowed on the system

  | |     

  | |__ Total free allocated file descriptors

  |

  |__ Total allocated file descriptors

To compute the number of file descriptors currently being used:

1380 - 180 = 1200

 

其他有用参数

NR_OPEN = Maximum number of open files per process

NR_FILE = Total number of files that can be open in the system at any time

FILE-MAX = Kernel parameter refers to maximum number of file descriptors allowed per system

FILE-NR = Refers to the number of current file descriptors used at any moment.

LSOF    = Gives the number of open files.

 

ulimit –a查看当前用户的shell limit 

若某些资源设置过小会导致系统无法正常提供服务


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值