• (转)linux 打开文件数 too many open files 解决方法


    too many open files

    出现这句提示的原因是程序打开的文件/socket连接数量超过系统设定值。

     

    查看每个用户最大允许打开文件数量

    ulimit -a

    1. fdipzone@ubuntu:~$ ulimit -a
    2. core file size (blocks, -c) 0
    3. data seg size (kbytes, -d) unlimited
    4. scheduling priority (-e) 20
    5. file size (blocks, -f) unlimited
    6. pending signals (-i) 16382
    7. max locked memory (kbytes, -l) 64
    8. max memory size (kbytes, -m) unlimited
    9. open files (-n) 1024
    10. pipe size (512 bytes, -p) 8
    11. POSIX message queues (bytes, -q) 819200
    12. real-time priority (-r) 0
    13. stack size (kbytes, -s) 8192
    14. cpu time (seconds, -t) unlimited
    15. max user processes (-u) unlimited
    16. virtual memory (kbytes, -v) unlimited
    17. file locks (-x) unlimited


    其中 open files (-n) 1024 表示每个用户最大允许打开的文件数量是1024 

    查看当前系统打开的文件数量

    1.  lsof | wc -l
       
    2.  watch "lsof | wc -l"
       

    查看某一进程的打开文件数量

    1.  lsof -p pid | wc -l
       
    2.  lsof -p 1234 | wc -l
       

    设置open files数值方法

    ulimit -n 2048

    1.  fdipzone@ubuntu:~$ ulimit -n 2048
       
    2.  fdipzone@ubuntu:~$ ulimit -a
       
    3.  core file size (blocks, -c) 0
       
    4.  data seg size (kbytes, -d) unlimited
       
    5.  scheduling priority (-e) 20
       
    6.  file size (blocks, -f) unlimited
       
    7.  pending signals (-i) 16382
       
    8.  max locked memory (kbytes, -l) 64
       
    9.  max memory size (kbytes, -m) unlimited
       
    10.  open files (-n) 2048
       
    11.  pipe size (512 bytes, -p) 8
       
    12.  POSIX message queues (bytes, -q) 819200
       
    13.  real-time priority (-r) 0
       
    14.  stack size (kbytes, -s) 8192
       
    15.  cpu time (seconds, -t) unlimited
       
    16.  max user processes (-u) unlimited
       
    17.  virtual memory (kbytes, -v) unlimited
       
    18.  file locks (-x) unlimited
       

    这样就可以把当前用户的最大允许打开文件数量设置为2048了,但这种设置方法在重启后会还原为默认值。

     

    永久设置方法

     

    vim /etc/security/limits.conf
    在最后加入
    * soft nofile 4096
    * hard nofile 4096

    最前的 * 表示所有用户,可根据需要设置某一用户,例如

     

    fdipzone soft nofile 8192
    fdipzone hard nofile 8192

    改完后注销一下就能生效。

    转自:https://blog.csdn.net/fdipzone/article/details/34588803

  • 相关阅读:
    Windows各个文件夹介绍
    Zabbix使用外部命令fping处理ICMP ping的请求
    QT 样式表实例
    QT 样式表基础知识
    cocos2d-js入门一
    try throw catch typeid
    cocos2d-x入门三 分层设计框架
    cocos2d-x入门二 helloworld实例运行与创建
    cocos2d-x入门一
    批量操作QT UI中的控件
  • 原文地址:https://www.cnblogs.com/heluan/p/9597636.html
Copyright © 2020-2023  润新知