LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 07-25-2007, 03:36 AM   #1
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 668
Blog Entries: 7

Rep: Reputation: 31
File Descriptors and Ulimits


Dear All
I have a couple of questions regarding file descriptors (handles) and the command ulimit.
Now the thing is I know about Ulimit..to get a snapshot about the file descriptors on the system I executed the following command :


[root@localhost mail]# cat /proc/sys/fs/file-nr
2520 0 206068
| | |
| | |
| | maximum open file descriptors permitted
| total free allocated file descriptors
total allocated file descriptors since boot

I took the appended descriptions from http://support.zeus.com/zws/faqs/200...iledescriptors
What I do not understand is that how these number are calculated if the total number of allocators since boot is 2520 and the available is 0 how can the
maximum open file descriptors permitted be bigger than that number?
I mean if the first number is used to describe the file allocators of one process in particular which is it ?

Another thing that confused me from the same article is the following phrase :

"In current (2.4+) Linux kernels, file descriptors are dynamically
created as necessary, but cannot be removed or reduced other than by
rebooting the server."

What does that mean, that in 2.4 kernels and above (I am using 2.6) file descriptors hang on to the process untill the system is rebooted..I think there is either something wrong with the way I understood this or ....

Can anyone shed some light on the issues mentioned above please ?
 
Old 07-25-2007, 07:46 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
The third number, the maximum number of file descriptors permitted, does not change while the system is running.

It isn't usually the case that this maximum number of file descriptors have all been allocated. That's why the first number is usually much smaller than the third number. New file descriptors are allocated as needed.

Let's say a process requests a file descriptor (by opening a file). Let's suppose that the second number, the total number of file descriptors which have already been allocated but are not currently being used, is greater than 0. Then one of these will be used for this request, and the first number (the number of allocated file descriptors) will not change, because a new file descriptor did not need to be allocated for this request. Instead, the second number would decrease by 1.

But let's suppose instead that the second number is 0. This would mean that all file descriptors which have been allocated are currently in use. In that case, the second number would be already be zero, so the OS doesn't decrease it by 1. Instead, the OS allocates a new file descriptor, and increases the first number by 1.

The OS never deallocates a file descriptor while it's running. When a process closes a file descriptor, that file descriptor becomes available for either the same process (while it exists) or another process. So it doesn't "hang on" to the process until reboot.

Try this shell script on a system that's quiet, that's not running very much:

Code:
#!/bin/bash

cat /proc/sys/fs/file-nr
cat /proc/sys/fs/file-nr < /dev/null
cat /proc/sys/fs/file-nr
When I tried it, I got these numbers:

Code:
1242    363     13107
1242    362     13107
1242    363     13107
See? When the shell script closed /dev/null, the second number increased by 1, and the file descriptor was made available for any process for use.

Hope this helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Increasing File Descriptors Geoffrey_Firmin Slackware 5 04-21-2008 10:48 AM
Socket File Descriptors for a process MadCoder77 Linux - Networking 0 05-26-2005 05:19 PM
file descriptors node047 Linux - Newbie 1 03-29-2005 06:47 AM
unix file descriptors versus c FILE pointers nodger Programming 9 11-25-2004 08:02 AM
File descriptors odd question ferreter Linux - General 2 02-13-2003 11:21 AM


All times are GMT -5. The time now is 10:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration