The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing a file descriptor robotball Shell Programming and Scripting 6 06-08-2008 11:41 PM
Problems with file descriptor teo High Level Programming 11 05-09-2005 12:47 PM
File Descriptor Help rahulrathod UNIX for Dummies Questions & Answers 3 10-14-2004 06:08 AM
file activity (open/closed) file descriptor info using KORN shell scripting Gary Dunn UNIX for Dummies Questions & Answers 3 06-07-2004 02:54 PM
bad file descriptor? ftb UNIX for Dummies Questions & Answers 1 02-20-2002 07:19 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-13-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
File descriptor constant

I have a requirement to close all the file descriptors from 3 to 1024 for a particular application.

Right now, this is how I do it ..

Code:
for ( int i = 3 ; i <= 1024; ++i )
close(i);

The change I am looking at is, I want to do away with the number 1024 and replace it with a constant which might be present in some header file. I need the name of the constant and the header file.

I tried looking into /usr/include/limits.h and /usr/include/ulimit.h

Did find anything I was looking for.

I am not looking for a

#define MAX_FILE_DESCRIPTORS 1024

either; i.e. the number should not depend on the user. Should be a system constant.

Any help appreciated.

Vino
  #2 (permalink)  
Old 05-13-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,127
That's not the way it works. It is, potentially, per process. You can call getrlimit to obtain the value.
  #3 (permalink)  
Old 05-16-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Using getrlimit and the appropriate constants, this is what I am using now.


Code:
struct rlimit RL;

getrlimit(RLIMIT_NOFILE, &RL)
  for ( int fd = 3; fd <= RL.rlim_cur; ++fd )
   close(fd);

Apparently rlim_cur and rlim_max gives me 1024 on my machine.

Thanks,
Vino
  #4 (permalink)  
Old 05-17-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,789
You misunderstand. A process can call setrlimit() and reduce the number of open file desriptors allowed by the process. Or it can be reduced for all users.

The kernel on some versions of unix can be reconfigured to allow more than 1024 open file descriptors.

The point: You cannot depend on 1024
  #5 (permalink)  
Old 05-18-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Jim,

I agree with you. And that is why, I took to getrlimit.

When I said

Apparently rlim_cur and rlim_max gives me 1024 on my machine.

I was just giving away information which was needed.

Vino
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0