Solved

File Descriptors - How many?

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

Industry Leaders: 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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

752 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