Solved

File Descriptors - How many?

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now