zoukankan      html  css  js  c++  java
  • 突破linux限制

    查看当前系统打开的文件数量: lsof | wc -l  
    查看当前进程的打开文件数量:lsof -p pid | wc -l      (lsof -p 1234 | wc -l  )

    查看当前进程的最大可以打开的文件数:cat /proc/PID/limits  (如果通过ulimit -n 设置或者修改/etc/security/limits.conf,看看进程是否生效)  

    查看系统总限制打开文件的最大数量:cat /proc/sys/fs/file-max

    lsof只能以root权限执行。在终端下输入lsof即可显示系统打开的文件,因为 lsof 需要访问核心内存和各种文件,所以必须以 root 用户的身份运行它才能够充分地发挥其功能。
    ————————————————

    用户级别:

    临时会话生效
    ulimit -n 65535

    永久生效
    1.在文件尾部添加如下代码:

    echo ulimit -n 65535 >>/etc/profile

    source /etc/profile

    ulimit -n

    2.修改linux的软硬件限制文件/etc/security/limits.conf,需要重新登录生效,不能在profile加ulimit。


    系统级别:sysctl.conf
    最后记得刷新立即生效

    echo fs.file-max = 1048576 >>/etc/sysctl.conf
    /sbin/sysctl -p

    sysctl -a | grep fs.file-max
    ----------------

    在/etc/sysctl.conf中添加如下配置:

    fs.file-max = 1048576
    net.ipv4.ip_local_port_range = 1024 65535
    net.ipv4.tcp_mem = 786432 2097152 3145728
    net.ipv4.tcp_rmem = 4096 4096 16777216
    net.ipv4.tcp_wmem = 4096 4096 16777216

    net.ipv4.tcp_tw_reuse = 1
    net.ipv4.tcp_tw_recycle = 1
    -----------

    cat /dev/null > /etc/security/limits.conf
    cat > /etc/security/limits.conf<< EOF
    * soft nofile  1048576
    * hard nofile  1048576
    * soft memlock -1
    * hard memlock -1
    * soft nproc   -1
    * hard nproc   -1
    * soft stack 10240
    * hard stack 32768
    EOF



  • 相关阅读:
    CSU 1122
    CSU 1256
    CSU 1240
    HDU 1874
    CSU 1004
    Problem F CodeForces 16E
    Problem E CodeForces 237C
    Problem C FZU 1901
    12-30
    2016-12-29
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/14952633.html
Copyright © 2011-2022 走看看