linux非root用户文件描述符限制

描述

在一次生产环境下切换非root用户,导致如下错误等待:

1
2
3
4
5
6
[root@xy_Tomcat_1 exam-service]# su - java
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable

通常上述问题发现是由于非root用户默认打开文件描述符为1024:

1
2
3
4
5
6
7
8
cat /etc/security/limits.d/90-nproc.conf

# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.

* soft nproc 1024
root soft nproc unlimited

解决

只要把非root用户值改为合适本身环境即可