Using standard C library sysconf is very simple.
See all about sysconf.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | NAME sysconf -- get configurable system variables LIBRARY Standard C Library (libc, -lc) SYNOPSIS #include long sysconf(int name); DESCRIPTION This interface is defined by IEEE Std 1003.1-1988 (``POSIX.1''). A far more complete interface is available using sysctl(3). The sysconf() function provides a method for applications to determine the current value of a configurable system limit or option variable. The name argument specifies the system variable to be queried. Symbolic con- stants for each name value are found in the include file . Shell programmers who need access to these parameters should use the getconf(1) utility. The available values are as follows: _SC_ARG_MAX The maximum bytes of argument to execve(2). _SC_CHILD_MAX The maximum number of simultaneous processes per user id. _SC_CLK_TCK The frequency of the statistics clock in ticks per second. _SC_IOV_MAX The maximum number of elements in the I/O vector used by readv(2), writev(2), recvmsg(2), and sendmsg(2). _SC_NGROUPS_MAX The maximum number of supplemental groups. _SC_NPROCESSORS_CONF The number of processors configured. _SC_NPROCESSORS_ONLN The number of processors currently online. _SC_OPEN_MAX The maximum number of open files per user id. _SC_PAGESIZE The size of a system page in bytes. _SC_STREAM_MAX The minimum maximum number of streams that a process may have open at any one time. _SC_TZNAME_MAX The minimum maximum number of types supported for the name of a timezone. _SC_JOB_CONTROL Return 1 if job control is available on this system, otherwise -1. _SC_SAVED_IDS Returns 1 if saved set-group and saved set-user ID is available, otherwise -1. _SC_VERSION The version of IEEE Std 1003.1 (``POSIX.1'') with which the sys- tem attempts to comply. _SC_BC_BASE_MAX The maximum ibase/obase values in the bc(1) utility. _SC_BC_DIM_MAX The maximum array size in the bc(1) utility. _SC_BC_SCALE_MAX The maximum scale value in the bc(1) utility. _SC_BC_STRING_MAX The maximum string length in the bc(1) utility. _SC_COLL_WEIGHTS_MAX The maximum number of weights that can be assigned to any entry of the LC_COLLATE order keyword in the locale definition file. _SC_EXPR_NEST_MAX The maximum number of expressions that can be nested within parenthesis by the expr(1) utility. _SC_LINE_MAX The maximum length in bytes of a text-processing utility's input line. _SC_RE_DUP_MAX The maximum number of repeated occurrences of a regular expres- sion permitted when using interval notation. _SC_2_VERSION The version of IEEE Std 1003.2 (``POSIX.2'') with which the sys- tem attempts to comply. _SC_2_C_BIND Return 1 if the system's C-language development facilities sup- port the C-Language Bindings Option, otherwise -1. _SC_2_C_DEV Return 1 if the system supports the C-Language Development Utili- ties Option, otherwise -1. _SC_2_CHAR_TERM Return 1 if the system supports at least one terminal type capa- ble of all operations described in IEEE Std 1003.2 (``POSIX.2''), otherwise -1. _SC_2_FORT_DEV Return 1 if the system supports the FORTRAN Development Utilities Option, otherwise -1. _SC_2_FORT_RUN Return 1 if the system supports the FORTRAN Runtime Utilities Option, otherwise -1. _SC_2_LOCALEDEF Return 1 if the system supports the creation of locales, other- wise -1. _SC_2_SW_DEV Return 1 if the system supports the Software Development Utili- ties Option, otherwise -1. _SC_2_UPE Return 1 if the system supports the User Portability Utilities Option, otherwise -1. These values also exist, but may not be standard: _SC_PHYS_PAGES The number of pages of physical memory. Note that it is possible that the product of this value and the value of _SC_PAGESIZE will overflow a long in some configurations on a 32bit machine. |
The source code is this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include #include main() { long tmp,tmp2; tmp=sysconf(_SC_NPROCESSORS_CONF); tmp2=sysconf(_SC_CLK_TCK); if(tmp==-1 && tmp2==-1) printf("Check the argument passed to sysconf"); else printf("Processors : %d \n",tmp); printf("Clock ticks/second: %d \n",tmp2); } |
I use stdio.h and unistd.h libs. Also, I have two vars tmp and tmp2.
This vars will take the result of _SC_NPROCESSORS_CONF and _SC_CLK_TCK using sysconf.
Use the gcc to make binary.
1 | $ gcc sysconf-test.c -o sysconf-test |
… run it and we see the output.
1 2 3 | $ ./sysconf-test Processors : 1 Clock ticks/second: 100 |
We can also use all of these available parameters.