Linux ulimit详解

ulimit 命令用来设置系统的资源限制。

1. 可以使用ulimit -a来查看系统各种资源的限制。如下:

>>> 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) 127966
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 100001
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) 127966
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

  

资源解释:

core file size(core 文件大小): 当程序崩溃时,会把程序内存数据保存到core文件中,便于事后debug。 core file默认为0,表示不打开。

 

2. 设置ulimit资源

>>> vim /etc/security/limits.conf

2.1 解除 Linux 系统的最大进程数和最大文件打开数限制:
        vi /etc/security/limits.conf
        # 添加如下的行
        * soft noproc 11000
        * hard noproc 11000
        * soft nofile 4100
        * hard nofile 4100
       说明:* 代表针对所有用户,noproc 是代表最大进程数,nofile 是代表最大文件打开数
2.2 修改所有 linux 用户的环境变量文件:
    vi /etc/profile
    ulimit -u 10000
    ulimit -n 4096
    ulimit -d unlimited
    ulimit -m unlimited
    ulimit -s unlimited
    ulimit -t unlimited
    ulimit -v unlimited
 保存后运行#source /etc/profile 使其生效
posted @ 2024-01-23 11:48  软件匠工  阅读(7)  评论(0编辑  收藏  举报