温馨提示×

centos ulimit怎么查看

小樊
56
2026-08-19 03:33:55
栏目: 智能运维

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


1️⃣ 查看当前 shell 的所有限制

ulimit -a

输出示例:

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
open files              (-n) 1024
pipe size               (512 bytes, -p) 8
...

2️⃣ 查看单个资源限制(常用)

查看最大打开文件数

ulimit -n

查看最大进程数

ulimit -u

查看 core 文件大小

ulimit -c

查看栈大小

ulimit -s

3️⃣ 查看系统级限制(不是 ulimit)

系统最大打开文件数

cat /proc/sys/fs/file-max

当前已打开文件数

cat /proc/sys/fs/file-nr

4️⃣ 查看某进程的实际限制(推荐)

查看正在运行的进程限制

cat /proc/<PID>/limits

例如:

cat /proc/1234/limits

5️⃣ 查看 systemd 服务的限制(CentOS 7+)

如果是 systemd 管理的服务:

systemctl show <服务名> | grep Limit

例如:

systemctl show nginx | grep Limit

6️⃣ 注意点(很重要)

  • ulimit 只对当前 shell 及其子进程生效
  • 修改方式:
    • 临时:ulimit -n 65535
    • 永久:
      vi /etc/security/limits.conf
      
      示例:
      * soft nofile 65535
      * hard nofile 65535
      

如果你是想排查 “too many open files”、“fork 失败” 或 “docker / java / nginx 限制”,可以告诉我具体场景,我可以给你更精确的查看和修改方案。

0 踩