Solved

File Descriptors - How many?

Posted on 1998-07-17
4
365 Views
Last Modified: 2010-04-21
I have a C++ program that is running on a unix machine.  I need to find out exactly how many file descriptors I have left.  I have a lot of socket connections opened and reading the output.  I am running into problems with some of the file descriptors I get a "Bad File Number".  I would like to exactly how many I have left.  Any ideas?

Is there a way to find out how many file descriptors I have left for the entire system as well as how many per process?
0
Comment
Question by:sgrobins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 2008862
#include <stdio.h>
define NFILE FOPEN_MAX
0
 
LVL 84

Expert Comment

by:ozo
ID: 2008863
#include <sys/resource.h>
struct rlimit rl;
getrlimit(RLIMIT_NOFILE,&rl);

#include <ulimit.h>
limit=ulimit(UL_GDESLIM);
0
 

Author Comment

by:sgrobins
ID: 2008864
I am using the gerlimit and setrlimit to set the maximum file descriptors allowed in my program.  I have set it to 1024.  What I would like to do is as the program is running see how many file descriptors are in use.  Is this possible?
0
 
LVL 1

Accepted Solution

by:
Rajkumar_R earned 100 total points
ID: 2008865
See the man page for select ! You can set all the bits from 0 to 1024  and using the call select you can check how many is readable how many is writable ...etc ...which ever is suitable to your logic !
eg:-

fd_set myfd;
FD_ZERO(&stFDset);      

for (i=0; i< 1024;i++ )
     FD_SET(i,&myfd);  

then call the select first to check how many is readable ..and then next to see how many is writable or both at once !

Please let me know if you need more details !

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question