Solved

File Descriptors - How many?

Posted on 1998-07-17
4
358 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
  • 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

785 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