Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

File Descriptors - How many?

Posted on 1998-07-17
4
Medium Priority
?
375 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 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

705 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