When your system has configurable system limits, you can use the sysconf function to find out the value that applies to any particular machine. The function and the associated parameter constants are declared in the header file unistd.h.
long int function>sysconf/function> (int parameter) This function is used to inquire about runtime system parameters. The parameter argument should be one of the _SC_ symbols listed below.
The normal return value from sysconf is the value you requested. A value of -1 is returned both if the implementation does not impose a limit, and in case of an error.
The following errno error conditions are defined for this function:
The value of the parameter is invalid.
Here are the symbolic constants for use as the parameter argument to sysconf. The values are all integer constants (more specifically, enumeration type values).
Inquire about the parameter corresponding to ARG_MAX.
Inquire about the parameter corresponding to CHILD_MAX.
Inquire about the parameter corresponding to OPEN_MAX.
Inquire about the parameter corresponding to STREAM_MAX.
Inquire about the parameter corresponding to TZNAME_MAX.
Inquire about the parameter corresponding to NGROUPS_MAX.
Inquire about the parameter corresponding to _POSIX_JOB_CONTROL.
Inquire about the parameter corresponding to _POSIX_SAVED_IDS.
Inquire about the parameter corresponding to _POSIX_VERSION.
Inquire about the parameter corresponding to CLOCKS_PER_SEC; the section called “CPU Time Inquiry”.
Inquire about the parameter corresponding to maximal length allowed for a character class name in an extended locale specification. These extensions are not yet standardized and so this option is not standardized as well.
Inquire about the parameter corresponding to _POSIX_REALTIME_SIGNALS.
Inquire about the parameter corresponding to _POSIX_PRIORITY_SCHEDULING.
Inquire about the parameter corresponding to _POSIX_TIMERS.
Inquire about the parameter corresponding to _POSIX_ASYNCHRONOUS_IO.
Inquire about the parameter corresponding to _POSIX_PRIORITIZED_IO.
Inquire about the parameter corresponding to _POSIX_SYNCHRONIZED_IO.
Inquire about the parameter corresponding to _POSIX_FSYNC.
Inquire about the parameter corresponding to _POSIX_MAPPED_FILES.
Inquire about the parameter corresponding to _POSIX_MEMLOCK.
Inquire about the parameter corresponding to _POSIX_MEMLOCK_RANGE.
Inquire about the parameter corresponding to _POSIX_MEMORY_PROTECTION.
Inquire about the parameter corresponding to _POSIX_MESSAGE_PASSING.
Inquire about the parameter corresponding to _POSIX_SEMAPHORES.
Inquire about the parameter corresponding to _POSIX_SHARED_MEMORY_OBJECTS.
Inquire about the parameter corresponding to _POSIX_AIO_LISTIO_MAX.
Inquire about the parameter corresponding to _POSIX_AIO_MAX.
Inquire the value by which a process can decrease its asynchronous I/O priority level from its own scheduling priority. This corresponds to the run-time invariant value AIO_PRIO_DELTA_MAX.
Inquire about the parameter corresponding to _POSIX_DELAYTIMER_MAX.
Inquire about the parameter corresponding to _POSIX_MQ_OPEN_MAX.
Inquire about the parameter corresponding to _POSIX_MQ_PRIO_MAX.
Inquire about the parameter corresponding to _POSIX_RTSIG_MAX.
Inquire about the parameter corresponding to _POSIX_SEM_NSEMS_MAX.
Inquire about the parameter corresponding to _POSIX_SEM_VALUE_MAX.
Inquire about the parameter corresponding to _POSIX_SIGQUEUE_MAX.
Inquire about the parameter corresponding to _POSIX_TIMER_MAX.
Inquire about the parameter corresponding to _POSIX_PII.
Inquire about the parameter corresponding to _POSIX_PII_XTI.
Inquire about the parameter corresponding to _POSIX_PII_SOCKET.
Inquire about the parameter corresponding to _POSIX_PII_INTERNET.
Inquire about the parameter corresponding to _POSIX_PII_OSI.
Inquire about the parameter corresponding to _POSIX_SELECT.
Inquire about the parameter corresponding to _POSIX_UIO_MAXIOV.
Inquire about the parameter corresponding to _POSIX_PII_INTERNET_STREAM.
Inquire about the parameter corresponding to _POSIX_PII_INTERNET_DGRAM.
Inquire about the parameter corresponding to _POSIX_PII_OSI_COTS.
Inquire about the parameter corresponding to _POSIX_PII_OSI_CLTS.
Inquire about the parameter corresponding to _POSIX_PII_OSI_M.
Inquire the value of the value associated with the T_IOV_MAX variable.
Inquire about the parameter corresponding to _POSIX_THREADS.
Inquire about the parameter corresponding to _POSIX_THREAD_SAFE_FUNCTIONS.
Inquire about the parameter corresponding to _POSIX_GETGR_R_SIZE_MAX.
Inquire about the parameter corresponding to _POSIX_GETPW_R_SIZE_MAX.
Inquire about the parameter corresponding to _POSIX_LOGIN_NAME_MAX.
Inquire about the parameter corresponding to _POSIX_TTY_NAME_MAX.
Inquire about the parameter corresponding to _POSIX_THREAD_DESTRUCTOR_ITERATIONS.
Inquire about the parameter corresponding to _POSIX_THREAD_KEYS_MAX.
Inquire about the parameter corresponding to _POSIX_THREAD_STACK_MIN.
Inquire about the parameter corresponding to _POSIX_THREAD_THREADS_MAX.
Inquire about the parameter corresponding toa _POSIX_THREAD_ATTR_STACKADDR.
Inquire about the parameter corresponding to _POSIX_THREAD_ATTR_STACKSIZE.
Inquire about the parameter corresponding to _POSIX_THREAD_PRIORITY_SCHEDULING.
Inquire about the parameter corresponding to _POSIX_THREAD_PRIO_INHERIT.
Inquire about the parameter corresponding to _POSIX_THREAD_PRIO_PROTECT.
Inquire about the parameter corresponding to _POSIX_THREAD_PROCESS_SHARED.
Inquire about whether the system has the POSIX.2 C compiler command, c89.
Inquire about whether the system has the POSIX.2 Fortran compiler command, fort77.
Inquire about whether the system has the POSIX.2 asa command to interpret Fortran carriage control.
Inquire about whether the system has the POSIX.2 localedef command.
Inquire about whether the system has the POSIX.2 commands ar, make, and strip.
Inquire about the maximum value of obase in the bc utility.
Inquire about the maximum size of an array in the bc utility.
Inquire about the maximum value of scale in the bc utility.
Inquire about the maximum size of a string constant in the bc utility.
Inquire about the maximum number of weights that can necessarily be used in defining the collating sequence for a locale.
Inquire about the maximum number of expressions nested within parentheses when using the expr utility.
Inquire about the maximum size of a text line that the POSIX.2 text utilities can handle.
Inquire about the maximum number of weights that can be assigned to an entry of the LC_COLLATE category order keyword in a locale definition. The GNU C library does not presently support locale definitions.
Inquire about the version number of POSIX.1 that the library and kernel support.
Inquire about the version number of POSIX.2 that the system utilities support.
Inquire about the virtual memory page size of the machine. getpagesize returns the same value (the section called “How to get information about the memory subsystem?”).
Inquire about the number of configured processors.
Inquire about the number of processors online.
Inquire about the number of physical pages in the system.
Inquire about the number of available physical pages in the system.
Inquire about the number of functions which can be registered as termination functions for atexit; the section called “Cleanups on Exit”.
Inquire about the parameter corresponding to _XOPEN_VERSION.
Inquire about the parameter corresponding to _XOPEN_XCU_VERSION.
Inquire about the parameter corresponding to _XOPEN_UNIX.
Inquire about the parameter corresponding to _XOPEN_REALTIME.
Inquire about the parameter corresponding to _XOPEN_REALTIME_THREADS.
Inquire about the parameter corresponding to _XOPEN_LEGACY.
Inquire about the parameter corresponding to _XOPEN_CRYPT.
Inquire about the parameter corresponding to _XOPEN_ENH_I18N.
Inquire about the parameter corresponding to _XOPEN_SHM.
Inquire about the parameter corresponding to _XOPEN_XPG2.
Inquire about the parameter corresponding to _XOPEN_XPG3.
Inquire about the parameter corresponding to _XOPEN_XPG4.
Inquire about the number of bits in a variable of type char.
Inquire about the maximum value which can be stored in a variable of type char.
Inquire about the minimum value which can be stored in a variable of type char.
Inquire about the maximum value which can be stored in a variable of type int.
Inquire about the minimum value which can be stored in a variable of type int.
Inquire about the number of bits in a variable of type long int.
Inquire about the number of bits in a variable of a register word.
Inquire the maximum length of a multi-byte representation of a wide character value.
Inquire about the value used to internally represent the zero priority level for the process execution.
Inquire about the maximum value which can be stored in a variable of type ssize_t.
Inquire about the maximum value which can be stored in a variable of type signed char.
Inquire about the minimum value which can be stored in a variable of type signed char.
Inquire about the maximum value which can be stored in a variable of type short int.
Inquire about the minimum value which can be stored in a variable of type short int.
Inquire about the maximum value which can be stored in a variable of type unsigned char.
Inquire about the maximum value which can be stored in a variable of type unsigned int.
Inquire about the maximum value which can be stored in a variable of type unsigned long int.
Inquire about the maximum value which can be stored in a variable of type unsigned short int.
Inquire about the parameter corresponding to NL_ARGMAX.
Inquire about the parameter corresponding to NL_LANGMAX.
Inquire about the parameter corresponding to NL_MSGMAX.
Inquire about the parameter corresponding to NL_NMAX.
Inquire about the parameter corresponding to NL_SETMAX.
Inquire about the parameter corresponding to NL_TEXTMAX.
We recommend that you first test for a macro definition for the parameter you are interested in, and call sysconf only if the macro is not defined. For example, here is how to test whether job control is supported:
int have_job_control (void) { #ifdef _POSIX_JOB_CONTROL return 1; #else int value = sysconf (_SC_JOB_CONTROL); if (value 0) /* If the system is that badly wedged, there's no use trying to go on. */ fatal (strerror (errno)); return value; #endif }
Here is how to get the value of a numeric limit:
int get_child_max () { #ifdef CHILD_MAX return CHILD_MAX; #else int value = sysconf (_SC_CHILD_MAX); if (value 0) fatal (strerror (errno)); return value; #endif }