0

Consider I have a process called a.out , In that process, i have opened the 10 files using a open() function.

Consider that time I get the last descriptor is 13. So I need to know is there is any way to find the last opened descriptor in the process.

For that I am using a getrlimit like this

   if(getrlimit(RLIMIT_NOFILE,&r1)<0)
              perror("error");

But when I am priting this I get 4096 in my system. SO Is there is any way to do this?

10
  • What is meant by "Consider that time I get the last descriptor is 13"? Jan 21, 2015 at 13:58
  • @RubixRechvin - After opening a 10 files, the last opened file got the file descriptor as 13.
    – Bhuvanesh
    Jan 21, 2015 at 14:00
  • 2
    4096 means the maximum file descriptor number that can be opened by this process + 1. Jan 21, 2015 at 14:00
  • @iharob - so how to i know the last opened files descriptor??
    – Bhuvanesh
    Jan 21, 2015 at 14:01
  • 3
    Keep track of the information if you need it. Jan 21, 2015 at 14:01

1 Answer 1

1

There is no (sensible) magic way to do this. You must remember it in a variable somewhere. Each time you open a file, update this variable.

(getrlimit with RLIMIT_NOFILE tells you how many files you can open, not how many you have opened).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.