---View the default maximum number of file handles for the system, which defaults to 1024
# Ulimit-n
1024
----See how many handles are open for the current process
# Lsof-n|awk ' {print $} ' |sort|uniq-c|sort-nr|more
131 24204
57 24244
57 24231 .....
The first column is the number of handles open, and the second column is the process ID.
You can view the process name based on the ID number.
# PS Aef|grep 24204
Nginx 24204 24162 99 16:15? 00:24:25/usr/local/nginx/sbin/nginx-s
Linux has hard limits and soft limits. You can set these two parameters by Ulimit. As follows, run the following command with the root user:
# ULIMIT-HSN 4096
In the above command, h specifies the hard size, s specifies the soft size, and n indicates the maximum number of open file handles that set a single process. Personally feel better not to exceed 4096, after all, the more open file handle number of response time will certainly be more slowly. After the number of handles is set, the default value is restored after the system restarts. If you want to permanently save, you can modify the. bash_profile file, you can modify the/etc/profile to add the above command to the last.
There are several ways to view the number of handles that a process occupies:
1 through CAT/PROC/PID/FD can view thread PID number open thread;
2 through lsof command,/usr/sbin/lsof-p 21404 command results as follows: Commands PID USER FD TYPE DEVICE SIZE NODE NAME
Vas 21404 root cwd DIR 8,3 4096 30195729/home/users/root/vas
Vas 21404 root RTD DIR 8,2 4096 2/
Vas 21404 root txt REG 8,3 112201650 30195914/home/users/root/vas
COMMAND: The name of the process
PID: Process Identifier
USER: Process Owner
FD: A file descriptor that the application recognizes by the file descriptor. such as CWD, TXT, etc.
Type: File types, such as DIR, REG, IPV4, FIEO, etc.
DEVICE: Specifies the name of the disk
Size: Sizes of files
Node: Index node (identity of file on disk)
Name: Open the exact name of the file
Alternatively, the lsof command can view the process of seizing the port (see below for a process occupied by Port 9001):
/usr/sbin/lsof-i: 9001