温馨提示×

centos ulimit怎样查看

小樊
45
2026-09-30 05:40:16
栏目: 智能运维

在 CentOS(以及大多数 Linux 发行版)中,ulimit 用于查看或设置 shell 及进程的资源限制。下面是常用的查看方法:


一、查看当前 shell 的所有资源限制

ulimit -a

示例输出:

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
open files              (-n) 1024
max user processes      (-u) 4096
...

二、查看某一类资源限制

1. 查看最大打开文件数(最常见)

ulimit -n

2. 查看最大进程数

ulimit -u

3. 查看 core 文件大小

ulimit -c

4. 查看栈大小

ulimit -s

常用参数说明

参数 含义
-a 查看所有限制
-n 打开文件数
-u 用户最大进程数
-c core 文件大小
-s 栈大小
-f 最大文件大小
-t CPU 时间

三、查看某个正在运行的进程的限制

方法 1:通过 /proc

cat /proc/<PID>/limits

例如:

cat /proc/1234/limits

方法 2:使用 prlimit

prlimit --pid <PID>

四、查看系统级限制(非 ulimit)

1. 系统最大打开文件数

cat /proc/sys/fs/file-max

2. 当前已打开文件数

cat /proc/sys/fs/file-nr

五、注意点

  • ulimit 只对当前 shell 及其子进程有效
  • 修改后新开 shell 不生效(除非写入配置)
  • 永久修改通常在:
    • /etc/security/limits.conf
    • /etc/security/limits.d/*.conf

如果你是想 查看某个服务(如 nginx / mysql)的 ulimit,或者 修改 ulimit,可以继续问我。

0 踩