zoukankan      html  css  js  c++  java
  • linux系统资源限制———ulimit命令

    简介

    Linux ulimit命令用于控制shell程序的资源。
    ulimit为shell内建指令,可用来控制shell执行程序的资源

    推荐:https://blog.csdn.net/skiwnc/article/details/84100095

    [root@server ~]# type ulimit
    ulimit 是 shell 内嵌
    

    用法及选项

    选项

    -a  显示目前资源限制的设定。
    -c <core文件上限>  设定core文件的最大值,单位为区块。
    -d <数据节区大小>  程序数据节区的最大值,单位为KB。
    -f <文件大小>  shell所能建立的最大文件,单位为区块。
    -H  设定资源的硬性限制,也就是管理员所设下的限制。
    -m <内存大小>  指定可使用内存的上限,单位为KB。
    -n <文件数目>  指定同一时间最多可开启的文件数。
    -p <缓冲区大小>  指定管道缓冲区的大小,单位512字节。
    -s <堆叠大小>  指定堆叠的上限,单位为KB。
    -S  设定资源的弹性限制。
    -t <CPU时间>  指定CPU使用时间的上限,单位为秒。
    -u <程序数目>  用户最多可开启的程序数目。
    -v <虚拟内存大小>  指定可使用的虚拟内存上限,单位为KB。
    

    ulimit -n 打开最大文件数

    常见的案例日志:java.net.SocketException:Too many open files

    ulimit -u 最大用户数

    #相关的配置文件(配置文件需要重启服务生效)
    
    /etc/security/limits.conf
    
    [root@server ~]# cat /etc/security/limits.conf |egrep -iv "(^#|^$)"
    * soft nofile 65536 
    * hard nofile 65536
    [root@server ~]# ulimit -a | grep "-n"
    open files                      (-n) 65536
    
    /etc/security/limits.d/20-nproc.conf
    
    [root@server ~]# cat /etc/security/limits.d/20-nproc.conf 
    # Default limit for number of user's processes to prevent
    # accidental fork bombs.
    # See rhbz #432903 for reasoning.
    
    *          soft    nproc     1024
    root       soft    nproc     unlimited
    [root@server ~]# su - du
    上一次登录:六 4月 11 11:39:30 CST 2020pts/0 上
    [du@server ~]$ ulimit -u
    1024
    
    

    ulimit -a 显示当前资源限制的设定

    [root@server ~]# ulimit -a
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 3820
    max locked memory       (kbytes, -l) 64
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 8192
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 3820
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    
    
  • 相关阅读:
    K
    A
    C
    E
    2020/9/14
    hdu5306 hdu3954 cf438D
    2020/9/10-9/11
    题解
    2020/8/31
    2020/8/30
  • 原文地址:https://www.cnblogs.com/du-z/p/12678549.html
Copyright © 2011-2022 走看看