zoukankan      html  css  js  c++  java
  • linux文件描述符open file descriptors与open files的区别

    http://blog.itpub.net/15480802/viewspace-734062

    什么是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'

    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 

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

    http://space.itpub.net/15480802/viewspace-720722   关于nofile/nproc的测试

     

    参考资料Open Files/Open File Descriptors [ID 787780.1]

     
     
  • 相关阅读:
    null in ABAP and nullpointer in Java
    SAP ABAP SM50事务码和Hybris Commerce的线程管理器
    Hybris service layer和SAP CRM WebClient UI架构的横向比较
    SAP ABAP和Linux系统里如何检查网络传输的数据量
    SAP CRM WebClient UI和Hybris的controller是如何被调用的
    SAP CRM和Cloud for Customer订单中的业务伙伴的自动决定机制
    SAP CRM WebClient UI和Hybris CommerceUI tag的渲染逻辑
    SAP BSP和JSP页面里UI元素的ID生成逻辑
    微信jsapi支付
    微信jsapi退款操作
  • 原文地址:https://www.cnblogs.com/zengkefu/p/5602723.html
Copyright © 2011-2022 走看看