ulimit -a
cat /proc/<PID>/limits
# 查看打开文件数
lsof | wc -l
# 查看进程数
ps -eLf | wc -l
# 查看内存使用
free -h
# 文件描述符
ulimit -n 65536
# 进程数
ulimit -u unlimited
编辑 /etc/security/limits.conf
文件:
* soft nofile 65536
* hard nofile 65536
* soft nproc 65536
* hard nproc 65536
对于特定用户:
username soft nofile 65536
username hard nofile 65536
对于某些系统,还需要修改:
# 文件描述符系统限制
echo "fs.file-max = 2097152" >> /etc/sysctl.conf
sysctl -p
# 进程数系统限制
echo "kernel.pid_max = 4194304" >> /etc/sysctl.conf
sysctl -p
编辑服务文件,添加:
[Service]
LimitNOFILE=65536
LimitNPROC=65536
然后重新加载:
systemctl daemon-reload
systemctl restart service-name
lsof -p <PID>
检查进程打开的文件通过以上方法,您应该能够有效诊断和解决Linux系统中的进程资源限制问题。