在 CentOS(以及大多数 Linux 发行版)中,ulimit 用于查看或设置 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
...
ulimit -n
ulimit -u
ulimit -c
ulimit -s
cat /proc/sys/fs/file-max
cat /proc/sys/fs/file-nr
cat /proc/<PID>/limits
例如:
cat /proc/1234/limits
如果是 systemd 管理的服务:
systemctl show <服务名> | grep Limit
例如:
systemctl show nginx | grep Limit
ulimit 只对当前 shell 及其子进程生效ulimit -n 65535vi /etc/security/limits.conf
示例:* soft nofile 65535
* hard nofile 65535
如果你是想排查 “too many open files”、“fork 失败” 或 “docker / java / nginx 限制”,可以告诉我具体场景,我可以给你更精确的查看和修改方案。