zoukankan      html  css  js  c++  java
  • 统计linux 下当前socket 的fd数量

    最近做了个项目,需要统计linux 下当前socket 的fd数量,总结如下:

    Linux中查看socket状态:

    IPV4      cat /proc/net/sockstat

    sockets: used 130
    TCP: inuse 64 orphan 0 tw 0 alloc 70 mem 3
    UDP: inuse 4 mem 0
    UDPLITE: inuse 0
    RAW: inuse 0

    FRAG: inuse 0 memory 0

    注:
    sockets: used:已使用的所有协议套接字总量
    TCP: inuse:正在使用(正在侦听)的TCP套接字数量。其值≤ netstat –lnt | grep ^tcp | wc –l
    TCP: orphan:无主(不属于任何进程)的TCP连接数(无用、待销毁的TCP socket数)
    TCP: tw:等待关闭的TCP连接数。其值等于netstat –ant | grep TIME_WAIT | wc –l
    TCP:alloc(allocated):已分配(已建立、已申请到sk_buff)的TCP套接字数量。其值等于netstat –ant | grep ^tcp | wc –l
    TCP:mem:套接字缓冲区使用量
    UDP:inuse:正在使用的UDP套接字数量
    RAW:
    FRAG:使用的IP段数量

    IPv6:cat /proc/net/sockstat6

    TCP6: inuse 4
    UDP6: inuse 0
    UDPLITE6: inuse 0
    RAW6: inuse 0
    FRAG6: inuse 0 memory 0

    1)Linux系统下,所有进程允许打开的最大fd数量。查询语句:

    /proc/sys/fs/file-max

    2)Linux系统下,所有进程已经打开的fd数量及允许的最大数量。查询语句:

    /proc/sys/fs/file-nr

    3)单个进程允许打开的最大fd数量.查询语句:

    ulimit -n

    4)单个进程(例如进程id为5454)已经打开的fd.查询语句:

    ls -l /proc/5454/fd/

  • 相关阅读:
    Tuesday / Wednesday = Increased Response
    脚本语言
    py2exe
    脚本语言
    访问者模式
    C调用lua脚本的效率测试
    Python编码规范
    py2exe
    Python编码规范
    访问者模式
  • 原文地址:https://www.cnblogs.com/cheyunhua/p/14211936.html
Copyright © 2011-2022 走看看