2011年4月13日

Find how many open file in Linux and setup the kernel limits

Because of the limits in the Linux system, you may encounter problem if there is lot of opened file or processes in the server. There are some ways to fix/improve/check.

Below are some of my studys:
To find out the process and opened filesSee: http://www.netadmintools.com/art295.html

Use "lsof" command, some examples:
# lsof |wc -l (Show you all open files, including files which are not using file descriptors - such as current working directories, memory mapped library files, and executable text files)

# lsof -n|awk '{print $2}'|sort|uniq -c |sort -nr|more (Sort and summary by PID)

Check the proc:
# cat /proc/sys/fs/file-nr (This command give you: total allocated/free/max file descriptors information)

If you what to see for particular process:
# ps -ef (found out the PID)
# cat /proc/{PID}/fd (show only the file decriptors for particular PID)
# lsof -n |awk '{print $2}'|grep {PID}|wc -l (Count all open file for particular PID)

NOTE: uniq -c, give you unique line with count
Setup the ulimit and limits.conf:
http://linux.vbird.org/linux_basic/0320bash.php#variable_ulimit
http://linux.vbird.org/linux_basic/0410accountmanager.php#limits

Tweak Limits.conf will give you more room for your server application
The parameter for the tweaking:
nproc - max number of processes
nofile - max number of open files

沒有留言:

發佈留言