sysconf - get configuration information at run time
Standard C library (libc, -lc)
#include <unistd.h>
long sysconf(int name);
POSIX allows an application to test at compile or run time whether certain options are supported, or what the value is of certain configurable constants or limits.
At compile time this is done by including <unistd.h> and/or <limits.h> and testing the value of certain macros.
At run time, one can ask for numerical values using the present function sysconf(). One can ask for numerical values that may depend on the filesystem in which a file resides using fpathconf(3) and pathconf(3). One can ask for string values using confstr(3).
The values obtained from these functions are system configuration constants. They do not change during the lifetime of a process.
For options, typically, there is a constant _POSIX_FOO that may be defined in <unistd.h>. If it is undefined, one should ask at run time. If it is defined to -1, then the option is not supported. If it is defined to 0, then relevant functions and headers exist, but one has to ask at run time what degree of support is available. If it is defined to a value other than -1 or 0, then the option is supported. Usually the value (such as 200112L) indicates the year and month of the POSIX revision describing the option. glibc uses the value 1 to indicate support as long as the POSIX revision has not been published yet. The sysconf() argument will be _SC_FOO. For a list of options, see posixoptions(7).
For variables or limits, typically, there is a constant _FOO, maybe defined in <limits.h>, or _POSIX_FOO, maybe defined in <unistd.h>. The constant will not be defined if the limit is unspecified. If the constant is defined, it gives a guaranteed value, and a greater value might actually be supported. If an application wants to take advantage of values which may change between systems, a call to sysconf() can be made. The sysconf() argument will be _SC_FOO.
We give the name of the variable, the name of the sysconf() argument used to inquire about its value, and a short description.
First, the POSIX.1 compatible values.
- ARG_MAX - _SC_ARG_MAX
- The maximum length of the arguments to the exec(3) family of functions. Must not be less than _POSIX_ARG_MAX (4096).
- CHILD_MAX - _SC_CHILD_MAX
- The maximum number of simultaneous processes per user ID. Must not be less than _POSIX_CHILD_MAX (25).
- HOST_NAME_MAX - _SC_HOST_NAME_MAX
- Maximum length of a hostname, not including the terminating null byte, as returned by gethostname(2). Must not be less than _POSIX_HOST_NAME_MAX (255).
- LOGIN_NAME_MAX - _SC_LOGIN_NAME_MAX
- Maximum length of a login name, including the terminating null byte. Must not be less than _POSIX_LOGIN_NAME_MAX (9).
- NGROUPS_MAX - _SC_NGROUPS_MAX
- Maximum number of supplementary group IDs.
- clock ticks - _SC_CLK_TCK
- The number of clock ticks per second. The corresponding variable is obsolete. It was of course called CLK_TCK. (Note: the macro CLOCKS_PER_SEC does not give information: it must equal 1000000.)
- OPEN_MAX - _SC_OPEN_MAX
- The maximum number of files that a process can have open at any time. Must not be less than _POSIX_OPEN_MAX (20).
- PAGESIZE - _SC_PAGESIZE
- Size of a page in bytes. Must not be less than 1.
- PAGE_SIZE - _SC_PAGE_SIZE
- A synonym for PAGESIZE/_SC_PAGESIZE. (Both PAGESIZE and PAGE_SIZE are specified in POSIX.)
- RE_DUP_MAX - _SC_RE_DUP_MAX
- The number of repeated occurrences of a BRE permitted by regexec(3) and regcomp(3). Must not be less than _POSIX2_RE_DUP_MAX (255).
- STREAM_MAX - _SC_STREAM_MAX
- The maximum number of streams that a process can have open at any time. If defined, it has the same value as the standard C macro FOPEN_MAX. Must not be less than _POSIX_STREAM_MAX (8).
- SYMLOOP_MAX - _SC_SYMLOOP_MAX
- The maximum number of symbolic links seen in a pathname before resolution returns ELOOP. Must not be less than _POSIX_SYMLOOP_MAX (8).
- TTY_NAME_MAX - _SC_TTY_NAME_MAX
- The maximum length of terminal device name, including the terminating null byte. Must not be less than _POSIX_TTY_NAME_MAX (9).
- TZNAME_MAX - _SC_TZNAME_MAX
- The maximum number of bytes in a timezone name. Must not be less than _POSIX_TZNAME_MAX (6).
- _POSIX_VERSION - _SC_VERSION
- indicates the year and month the POSIX.1 standard was approved in the format YYYYMML; the value 199009L indicates the Sept. 1990 revision.
The return value of sysconf() is one of the following:
- •
- On error, -1 is returned and errno is set to indicate the error (for example, EINVAL, indicating that name is invalid).
- •
- If name corresponds to a maximum or minimum limit, and that limit is indeterminate, -1 is returned and errno is not changed. (To distinguish an indeterminate limit from an error, set errno to zero before the call, and then check whether errno is nonzero when -1 is returned.)
- •
- If name corresponds to an option, a positive value is returned if the option is supported, and -1 is returned if the option is not supported.
- •
- Otherwise, the current value of the option or limit is returned. This value will not be more restrictive than the corresponding value that was described to the application in <unistd.h> or <limits.h> when the application was compiled.
For an explanation of the terms used in this section, see attributes(7).
| Interface | Attribute | Value |
| sysconf () | Thread safety | MT-Safe env |
It is difficult to use ARG_MAX because it is not specified how much of the argument space for exec(3) is consumed by the user's environment variables.
Some returned values may be huge; they are not suitable for allocating memory.