sysconf() — Determine system configuration options
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
Format
#define _POSIX_SOURCE
#include <unistd.h>
long sysconf(int name);
General description
- int name
-
Specifies the system configuration option to be obtained. The value of name can be any one of the following set of symbols defined in the unistd.h header file, each corresponding to a system configuration option:
The following are available when _POSIX_SOURCE is defined.
- _SC_ARG_MAX
- Represents ARG_MAX, as defined by the values returned by sysconf(), the maximum number of bytes of arguments and environment data that can be passed in an exec function.
- _SC_CHILD_MAX
- Represents CHILD_MAX, as defined by the values returned by sysconf(), the maximum number of processes that a real user ID (UID) may have running simultaneously.
- _SC_CLK_TCK
- Represents the CLK_TCK macro defined in the time.h header file: the number of clock ticks in a second.
- _SC_JOB_CONTROL
- Represents the _POSIX_JOB_CONTROL macro that can be defined in the unistd.h header file. This indicates that certain job control operations are implemented by this version of the operating system. If _POSIX_JOB_CONTROL is defined, various functions (for example, setpgid()) have more functionality than when the macro is not defined.
- _SC_NGROUPS_MAX
- Represents NGROUPS_MAX, as defined by the values returned by sysconf(), the maximum number of supplementary group IDs (GIDs) that can be associated with a process.
- _SC_OPEN_MAX
- Represents OPEN_MAX, as defined by the values returned by sysconf(), the maximum number of files that a single process can have open at one time.
- _SC_SAVED_IDS
- Represents the _POSIX_SAVED_IDS macro, which may be defined in unistd.h header file, indicating that this POSIX implementation has a saved set UID and a saved set GID. This symbol affects the behavior of such functions as setuid() and setgid().
- _SC_STREAM_MAX
- Represents the _STREAM_MAX macro, which may be defined in the unistd.h header file, indicating the maximum number of streams that a process can have open at one time.
- _SC_THREADS_MAX_NP
- Represents the THREAD_MAX macro, as defined by the values returned by sysconf(), the maximum number of concurrent threads processed by pthread_create(), including running, queued, and exited undetached threads in the caller's process.
- _SC_THREAD_TASKS_MAX_NP
- Represents the THREAD_TASKS_MAX macro, as defined by the values returned by sysconf(), the maximum number of MVS™ tasks simultaneously in use for threads processed by pthread_create() in the caller's process.
- _SC_TTY_GROUP
- Retrieves the group number associated with the TTYGROUP() initialization parameter.
- _SC_TZNAME_MAX
- Represents the _TZNAME_MAX macro, which may be defined in the unistd.h header file, indicating the maximum length of the name of a time zone.
- _SC_VERSION
- Represents the _POSIX_VERSION macro, which will be defined in the unistd.h header file, indicating the version of the POSIX.1 standard that the system conforms to.
In addition to the symbols exposed by _POSIX_SOURCE, the following are visible when _XOPEN_SOURCE is defined:
- _SC_XOPEN_CRYPT
- Represents _XOPEN_CRYPT, the implementation supports the X/Open Encryption Option Group.
- _SC_XOPEN_VERSION
- Represents _XOPEN_VERSION, integer value indicating version of the X/Open Portability Guide to which the implementation conforms.
- _SC_PASS_MAX
-
Represents PASS_MAX, as defined by the values returned by sysconf(), the maximum number of bytes allowed in a password, PassTicket, or password phrase.
Note:It was part of the Legacy Feature in Single UNIX Specification, Version 2, but has been withdrawn and is not supported as part of Single UNIX Specification, Version 3.
If it is necessary to continue using this function in an application written for Single UNIX Specification, Version 3, define the feature test macro _UNIX03_WITHDRAWN before including any standard system headers. The macro exposes all interfaces and symbols removed in Single UNIX Specification, Version 3.
In addition to the symbols exposed by _XOPEN_SOURCE, the following are visible when _XOPEN_SOURCE_EXTENDED is defined to be 1:
- _SC_PAGE_SIZE
- Returns the current page size in bytes.
- _SC_PAGESIZE
- Returns the current page size in bytes.
In addition to the symbols exposed by _POSIX_SOURCE, the following are visible when _POSIX_C_SOURCE is defined to be 2:
- _SC_2_C_BIND
- Represents _POSIX2_C_BIND, the implementation supports the C-Language Binding option.
- _SC_2_C_DEV
- Represents _POSIX2_C_DEV, the implementation supports the C-Language Development Utilities option.
- _SC_2_LOCALEDEF
- Represents _POSIX2_LOCALEDEF, the implementation supports the creation of locales by the localedef utility.
- _SC_2_UPE
- Represents _POSIX2_UPE, the implementation supports the User Portability Utilities option. .
- _SC_2_VERSION
- Represents _POSIX2_VERSION, integer value indicating version of the Shell and Utilities to which the implementation conforms.
In addition to the symbols exposed by _POSIX_C_SOURCE defined to be 2, the following are visible when _POSIX_C_SOURCE is defined to be 200112L:
- _SC_HOST_NAME_MAX
- Represents HOST_NAME_MAX, Maximum length of a host name (not including the terminating null) as returned from the gethostname() function.
- _SC_IPV6
- Represents _POSIX_IPV6, the implementation supports the IPv6 option.
- _SC_LOGIN_NAME_MAX
- Represents LOGIN_NAME_MAX, Maximum length of a login name.
- _SC_READER_WRITER_LOCKS
- Represents _POSIX_READER_WRITER_LOCKS, the implementation supports the Read-Write Locks option. This is always set to a value greater than zero if the Threads option is supported.
- _SC_REGEXP
- Represents _POSIX_REGEXP, the implementation supports the Regular Expression Handling option.
- _SC_SHELL
- Represents _POSIX_SHELL, the implementation supports the POSIX shell.
- _SC_SYMLOOP_MAX
- Represents SYMLOOP_MAX, maximum number of symbolic links that can be reliably traversed in the resolution of a path name in the absence of a loop.
- _SC_THREAD_ATTR_STACKSIZE
- Represents _POSIX_THREAD_ATTR_STACKSIZE, the implementation supports the Thread Stack Size Attribute option.
- _SC_THREAD_KEYS_MAX
- Represents PTHREAD_KEYS_MAX, maximum number of data keys that can be created by a process.
- _SC_THREAD_PROCESS_SHARED
- Represents _POSIX_THREAD_PROCESS_SHARED, the implementation supports the Thread Process-Shared Synchronization option.
- _SC_THREAD_SAFE_FUNCTIONS
- Represents _POSIX_THREAD_SAFE_FUNCTIONS, the implementation supports the Thread-Safe Functions option.
- _SC_THREAD_STACK_MIN
- Represents PTHREAD_STACK_MIN, minimum size in bytes of thread stack storage.
- _SC_THREAD_THREADS_MAX
- Represents PTHREAD_THREADS_MAX, maximum number of threads that can be created per process.
- _SC_THREADS
- Represents _POSIX_THREADS, the implementation supports the Threads option.
- _SC_TTY_NAME_MAX
- Represents TTY_NAME_MAX, maximum length of terminal device name.
- _SC_V6_ILP32_OFF32
- Represents _POSIX_V6_ILP32_OFF32, the implementation provides a C-language compilation environment with 32-bit int, long, pointer, and off_t types.
- _SC_V6_ILP32_OFFBIG
- Represents _POSIX_V6_ILP32_OFFBIG, the implementation provides a C-language compilation environment with 32-bit int, long, and pointer types and an off_t type using at least 64 bits.
- _SC_V6_LP64_OFF64
- Represents _POSIX_V6_LP64_OFF64, the implementation provides a C-language compilation environment with 32-bit int and 64-bit long, pointer, and off_t types.
- _SC_V6_LPBIG_OFFBIG
- Represents _POSIX_V6_LPBIG_OFFBIG, the implementation provides a C-language compilation environment with an int type using at least 32 bits and long, pointer, and off_t types using at least 64 bits.
- _SC_XOPEN_LEGACY
- Represents _XOPEN_LEGACY, the implementation supports the Legacy Option Group.
The following symbols are available under _XOPEN_SOURCE 500:
- _SC_GETPW_R_SIZE_MAX
- Maximum size of getpwuid_r() and getpwnam_r() data buffers
- _SC_GETGR_R_SIZE_MAX
- Maximum size of getgrgid_r() and getgrnam_r() data buffers
Returned value
If successful, sysconf() returns the value associated with the specified option.
If the variable corresponding to name exists but is not supported by the system, sysconf() returns -1 but does not change the value of errno. If sysconf() fails in some other way, it returns -1.
- Error Code
- Description
- EINVAL
- The value specified for the name argument is incorrect.
Example
/* CELEBS61
This example determines the value of ARG_MAX.
*/
#define _POSIX_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
main() {
long result;
errno = 0;
puts("examining ARG_MAX limit");
if ((result = sysconf(_SC_ARG_MAX)) == -1)
if (errno == 0)
puts("ARG_MAX is not supported.");
else perror("sysconf() error");
else
printf("ARG_MAX is %ld\n", result);
}
examining ARG_MAX limit
ARG_MAX is 1048576