In my program I'm storing some data related to the file descriptor in an array using file descriptors value as the index. so if I create an array with size equal to the soft limit of opened file descriptors, I will have array indexes from 0 - (soft limit-1). My question is can a value of file descriptor go beyond this index range? (i'm using ubuntu 20.4 and c language).
Yes, it can. The soft limit is something you can change with a call to ulimit(2)
system call.... so you can put it under the number of actually open files and that mean that open(2)
will fail on the next open, but it doesn't affect the actual number of open files you have open now. anyway... let's imagine this scenario:
you can still open 25 files more (you have 50 open files now)... and the'll go in the range 0 to 24, but the others continue to be open from 50 to 99. And you cannot open more files, because you run out the limit of open files.
By the way, the descriptor you get from the system from an open system call is always the minimum value available number to get... so, if you avoid touching the ulimits maximum number of open files, then you can do what you want.