View the number of file handles opened by a process under Linux

--View the system default maximum number of file handles, the system default is 1024

# ulimit -n

1024

 

----Check how many handles are opened by the current process

# lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr|more

131 24204 

57 24244  

57 24231   ........

where the first column is the number of open handles 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 and soft limits. These two parameters can be set through ulimit. The method is as follows, run the following command as root user:

# ulimit -HSn 4096

In the above command, H specifies the hard size, S specifies the soft size, and n represents the maximum number of open file handles for a single process. Personally, I think it is best not to exceed 4096. After all, the more the number of open file handles, the slower the response time will definitely be. After setting the number of handles, the default value will be restored after the system restarts. If you want to save it permanently, you can modify the .bash_profile file, you can modify /etc/profile and add the above command to the end

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326284965&siteId=291194637