krish – 起死回生 [Wake up from death & return to life.]

February 15, 2010

Working with file descriptors on *nix

Filed under: GNU/Linux — krish @ 6:05 pm
Tags: ,

Most of us would have encountered “Max number of open files” or related errors, where in processes fail to open more temporary files/sockets due to the limit on number of allowed files.

Let’s take a tour of how we tweak this on Linux

“File Descriptors are data structures used by programs to get handles on files.

Sum of file descriptors used by all processes cannot exceed the max limit at the OS level.

Each process has a limit on number of file descriptor it can use.”

NOTE: Increasing File descriptors limits can increase memory utilization and thus make the server instable.

Also, the number of file descriptors created cannot be removed without rebooting the box.

Let’s go now:

1. To see the max number of open file descriptors allowed system wide

[root@joshua ~]# cat /proc/sys/fs/file-max
1573026

2. To know how many file descriptors are being used

[root@lin-c1u33-zabbix-01 ~]# cat /proc/sys/fs/file-nr
2550    0       1573026

Here:

2550: the total number of file descriptors allocated since boot

0:  I am yet to find out what this really means. There are weird theories all over the place.

1573026: Max open file descriptors

3. The number of open files by a particular process. ( for example ldap )

[root@joshua ~]# ps aux | grep ldap
ldap     16094 10.8  0.7 351048 129056 ?       Ssl  04:10   7:31 /usr/sbin/slapd -h ldap:/// -u ldap
root     19023  0.0  0.0  61152   744 pts/12   S+   05:19   0:00 grep ldap
[root@joshua ~]# lsof | grep 16094 | wc -l
54

or
[root@joshua ~]# ls -l /proc/16094/fd | wc -l
18

The LDAP process has only 18 open file descriptors but, 54 open files associated with it.

Open files which are not using file descriptors would be library files, the program executable (binary), et all.

The count of these files are maintained in the kernel data structures, and can be seen using `cat /proc/PID/maps`, but they are not using file descriptors and so do not count in the kernel’s file descriptor list.

4. To change the limit on number of open file descriptors you can have,

[root@joshua ~]# echo “1234567” > /proc/sys/fs/file-max


***This post has More to come… ***

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Please leave a Reply / Discuss this topic here :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

The Male Factor

On behalf of the ignored gender

Rough Draft

by Atteris Amarth and Darrek Ringo

The Kochi Post.

Read by all + Influenced by none

JumboMake

A signature of Kiran

SAAYAM CHEDDAM FOUNDATION

This blog is just for additional and extension share of it's main frames. No activity is planned from here

krish - 起死回生 [Wake up from death & return to life.]

Get a sneak peek into krish's life, work and passion.

WordPress.com

WordPress.com is the best place for your personal blog or business site.

A Tale of Two and a Half

Monika Amita Bakshi

%d bloggers like this: