我有一个以 root 身份运行的进程,其打开文件数上限为 1024(实际上 lsof 显示其最大为 1031),但我找不到可以修改此限制的文件。
以下是 cat /proc/PID/limits 的输出以确认这一点
#cat /proc/32531/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 515045 515045 processes
Max open files 1024 4096 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 515045 515045 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
但是,我在“经典”配置文件中找不到该限制:
#cat /proc/sys/fs/file-max
13106306
#ulimit -S -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) 515045
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65536
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) 515045
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
#ulimit -H -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 515045
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65536
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) unlimited
cpu time (seconds, -t) unlimited
max user processes (-u) 515045
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
/etc/security/limits.conf 已完全注释,而 /etc/security/limits.d/ 为空
我在 Linux 版本 3.14.32-xxxx-grs-ipv6-64 上运行 debian 8.8(jessie)([电子邮件保护])(gcc 版本 4.9.2(Debian 4.9.2-10))
谢谢,
答案1
这是由 systemd 启动的进程吗?systemd 使用自己的限制,而不使用 limits.conf (pam_limits) 中的值。您必须设置LimitNOFILE 指令来增加它。
如果单元文件中或全局中没有该指令/etc/systemd/system.conf
,则 systemd 将记下现有的限制当它(init 进程,进程 1)由内核启动时。这在 Linux 内核中被硬编码为软限制 1024 和硬限制 4096自版本 2.6.39 起。