The number of handles held by the system process is viewed under linux

  • 2020-05-13 04:21:53
  • OfStack

-- view the default maximum number of file handles, which is 1024

# ulimit -n

1024

-- view how many handles the current process has open

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

131, 24204,

57, 24244

57 24231...

Where column 1 is the number of open handles and column 2 is the process ID.

You can view the process name by ID number.

# ps aef|grep 24204

99 16:15 ? 00:24:25 / usr/local/nginx/sbin/nginx - s

Linux has hard and soft limits. These two parameters can be set by ulimit. Run the following command as an root user:

# ulimit -HSn 4096

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


Related articles: