Solaris[TM] File descriptors - Solaris[TM] 2.4 through Solaris[TM] 11
Last updated on JUNE 02, 2017
Applies to:Solaris Operating System - Version 8 6/00 U1 to 11.3 [Release 8.0 to 11.0]
***Checked for relevance on 01-M ay-2014***
About File Descriptors
Processes interface with files through file-related system calls. The file-related system calls identify files by two means: their path name in the file system and a file descriptor. A file descriptor is an integer number identifying an open file within a process. Each process has a table of open files, starting at file descriptor 0 and progressing upward as more files are opened. A file descriptor can be obtained with the open() system call, which opens a file named by a path name and returns a file descriptor identifying the open file.
fd = open("/etc/passwd", flag, mode);
Once a file has been opened, a file descriptor can be used for operations on the file. The read(2) and write(2) operations provide basic file I/O, along with several other advanced mechanisms for performing more complex operations. A file descriptor is eventually closed by the close(2) system call or by the process' exit. By default, file descriptors 0, 1, and 2 are opened automatically by the C runtime library and represent the standard input, standard output, and standard error streams for a process.
In 2.3 and earlier releases, the only way to permanently change the default number of file descriptors that a process can open was to use adb on the kernel. In 2.4 and above, this can now be done through the /etc/system file.
The kernel establishes default hard and soft limits for the number of files a process can have opened at any one time. rlim_fd_max is the hard limit, and rlim_fd_cur is the current limit (or soft limit). A process can have up to rlim_fd_cur file descriptors and can increase the number up to rlim_fd_max. You can set these parameters system-wide by placing entries in the /etc/system file:
You can also alter the per-process limits either directly from the command line with the limit(1) or ulimit(1) shell commands, or programmatically with setrlimit(2). The actual number of open files that a process can maintain is largely determined by the file APIs used. For 32-bit systems, the the stdio(3S) interfaces are used, the limit is 256 open files. This limit results from the data type used in the FILE structure for the actual file descriptor. An unsigned 8-bit data type, which has a range of values of 0-255, is used. Thus, the maximum number of file descriptors is limited to 256 for 32-bit stdio(3S)-based programs. For 64-bit systems(and 64-bit processes), the stdio(3S) limit is 64 Kbytes."
The select(3C) interface, which provides a mechanism for polling, imposes another API limit. select(3C) limits the number of open files to 1 Kbyte on 32-bit systems, with the exception of 32-bit Solaris 7 [and later]. In 32-bit Solaris 7, select(3C) can poll up to 64-Kbyte file descriptors. If you use file descriptors greater than 1-Kbyte with select(3C) on 32-Bit Solaris 7 [or later], then you must declare FD_SETSIZE in the program code. On 64-bit Solaris 7, a 64-bit process has a default file descriptor set size (FD_SETSIZE) of 64Kbytes. Table 11-2 summarizes file descriptor limitations.
The following table shows the default and maximum values for the soft
and hard limits.
|OS Version||Default Limit||Default Hard Limit||Max for stdio^||Max for select^^|
|Solaris 7 (32-bit)||64||1024||256||65535 (with recomplie)^^|
|Solaris 7 (64-bit)||64||1024||256||65535|
|Solaris 8 (32-bit)||256||1024||256||65535 (with recompile)^^|
|Solaris 8 (64-bit)||256||1024||256||65535|
|Solaris 9 (32-bit)||256||65535||256||65535(with recompile)^^|
|Solaris 9 (64-bit)||256||65535||256||65535|
|Solaris 10 (64-bit)||256||65535||256||65535|
The soft limit (default limit) has to remain lower or equal to the hard limit.
^ See "The procedure to change file descriptor limit" below.
^^ Refers to paragraph above.
Sign In with your My Oracle Support account
Don't have a My Oracle Support account? Click to get started
Million Knowledge Articles and hundreds of Community platforms