zoukankan      html  css  js  c++  java
  • 文件描述符FD的含义/文件句柄

    使用sudo lsof -nP -iTCP -sTCP:LISTEN查看占用端口的程序;因为 lsof 需要访问核心内存和各种文件,所以必须以 root 用户的身份运行它才能够充分地发挥其功能

    概念

    文件句柄是windows系统的概念,在linux下称之为文件描述符FD(file description)

    常用命令

    sort -nr 安装数字逆序排列 -n number -r reverse
    uniq -c 统计相同项的数量,分两列显示,左列显示数量,右列显示内容 -c count

    1)统计各进程打开FD数:lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr
    
    2)统计各用户打开FD数:lsof -n|awk '{print $3}'|sort|uniq -c|sort -nr
    
    3)统计各命令打开FD数:lsof -n|awk '{print $1}'|sort|uniq -c|sort -nr
    

    单个进程的可用文件描述符的最大数量

    ulimit -n
    ulimit -a
    

    强大的工具 lsof

    man lsof

    可以查看fd/type等各个字段的含义

    FD:文件描述符,应用程序通过文件描述符识别该文件

    1)cwd:表示 current  work dirctory,即:应用程序的当前工作目录,这是该应用程序启动的目录,除非它本身对这个目录进行更改
    
    2)txt:该类型的文件是程序代码,如应用程序二进制文件本身或共享库,如上列表中显示的 /sbin/init  程序
    
    3)lnn: library references (AIX)
    
    4)er:  FD  information  error (see  NAME  column)
    
    5)jld:  jail  directory(FreeBSD)
    
    6)ltx: shared  library text(code and  data)
    
    7)mxx: hex  memory-mapped  type number  xx.
    
    8)m86:DOS  Merge  mapped  file
    
    9) mem: memory-mapped  file 
    
    10)mmap: memory-mapped device
    
    11)pd: parent  directory
    
    12)rtd: root  directory
    
    13)tr: kernel  trace file (OpenBSD)
    
    14)v86  VP/ix  mapped  file
    
    15)0:表示标准输出
    
    16)1:表示标准输入
    
    17)2:表示标准错误
    
    一般在标准输出、标准错误、标准输入后还跟着文件状态模式:r/w/u 等
    
    1)u:表示该文件被打开并处于读取/写入模式
    
    2)r:表示该文件被打开并处于只读模式
    
    3)w:表示该文件被打开并处于只写入模式
    
    4)空格:表示该文件的状态模式为 unknown ,且没有锁定
    
    5)- : 表示该文件的状态模式为 unknown ,且被锁定
    
    同时在文件状态模式后面,还跟着相关的锁
    
    1)N:for  a  Solaris NFS lock of  unknown  type
    
    2)r: for  a   read  lock on part  of the file 
    
    3)R:for a read  lock on the entire  file 
    
    4)w: for a write lock on part of the file (文件的部分写锁)
    
    5)W: for  a write  lock on the entire file(整个文件的写锁)
    
    6)u: for  a read and write lock of any length
    
    7)U: for a  lock of unknown type
    
    8)x: for an  SCO  OpenServer  Xenix  lock on part of the file 
    
    9)X:for an SCO OpentServer Xenix  lock on the entire  file
    
    10)space : if there is no  lock
  • 相关阅读:
    python——时间与时间戳之间的转换
    Python3中正则模块re.compile、re.match及re.search
    javascript 模块化开发
    Python细说 xrange 和 range 的区别
    PyInstaller 生成exe文件
    win10安装mysql5.7.14winx64遇到服务无法启动问题解决方法
    Python 自定义队列 数据结构
    spring事务使用心得
    LS 存取文件
    Single Instance Application
  • 原文地址:https://www.cnblogs.com/shengulong/p/11598297.html
Copyright © 2011-2022 走看看