SoFunction
Updated on 2025-04-16

Detailed explanation of the maximum number of threads and handles in Linux

The maximum number of threads and handles in Linux

Recently, some users reported that they had logged into CentOS 7 system.

Execute any command and report an error:

bash: fork:retry: No child processes
bash: fork: Resource temporarily unavailable

I saw this suspicion that it was caused by the system ulimit restrictions.

So check /etc/security/ and /etc/security//

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4
*       soft    nofile  327680
*       hard    nofile  327680

# End of file

In CentOS 7

ulimitofnprocParameters limit the total number of processes and threads that the user can create.

This is because in the Linux kernel, threads are implemented through lightweight processes (LWP), each thread will occupy a process number (PID), so it will be counted intonprocLimited scope

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

*          soft    nproc     4096
root       soft    nproc     unlimited

I found that the system has the largest number of processes and the maximum number of threads by default except root users, so has the user started too many processes or threads.

So through top and top -H, we checked the system process number 300+ and the number of threads number 4100+, and found that top -H found that the user started too many threads, which led to the reason.

Replenish

The number of threads occupied by the user can be obtained by the following command

1. ps

#ps -U <username> -L | wc -l

2. top

#top -H

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.