File descriptor constant


 
Thread Tools Search this Thread
Top Forums Programming File descriptor constant
# 1  
Old 05-13-2005
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  
Old 05-13-2005
That's not the way it works. It is, potentially, per process. You can call getrlimit to obtain the value.
# 3  
Old 05-16-2005
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  
Old 05-17-2005
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  
Old 05-18-2005
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
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Programming

[Makefile]File + constant problem

Hi guys, I am writing a Makefile with some strange features. What I have is: list of files *.efi list of guids (guid is just a number) one *.efi file is supposed to be used with one guid, so efi file and guid is a pair. What I need is: list of files *.fv How to make *.fv file... (1 Reply)
Discussion started by: Chrisdot
1 Replies

2. Shell Programming and Scripting

file descriptor KSH

Hello, How can i use file descriptor in a script to read 2 files at the same time and extract line 200 from file 1 and line 500 from file 2. Thanks. (6 Replies)
Discussion started by: LiorAmitai
6 Replies

3. Shell Programming and Scripting

Reading from one file and updating other file with constant entries

Hi All, Thaks for the help in my last thread. I have one more question. I have two files with ldap entries in it. One file contains all the user LDAP parameter entries (26 MB) and other file contains only the user id's that have to be inactivated. Unix script has to read from the file that has... (8 Replies)
Discussion started by: Samingla
8 Replies

4. UNIX for Dummies Questions & Answers

File Descriptor

Hi What the below path contains? /proc/<pid>/fd (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

5. Shell Programming and Scripting

File Descriptor

Hello All, Im opening a file desciptor in perl and sending data using print CMD "$xyz". is there a limit to the length of the string that I can give to this CMD at a time. (3 Replies)
Discussion started by: rimser9
3 Replies

6. UNIX for Dummies Questions & Answers

File Descriptor Help

What is a file descriptor in Unix?? How to find a file descriptor of a file in Unix?? Does it have anything to do with the Inode numbers?? (3 Replies)
Discussion started by: rahulrathod
3 Replies

7. UNIX for Dummies Questions & Answers

file activity (open/closed) file descriptor info using KORN shell scripting

I am trying to find a way to check the current status of a file. Such as some cron job processes are dependent on the completion of others. if a file is currently being accessed / modified or simply open state I will wait until it is done being processed before attempting the next process on that... (3 Replies)
Discussion started by: Gary Dunn
3 Replies
Login or Register to Ask a Question