Reference

sysctl(8)

get or set kernel state

NAME

sysctl – get or set kernel state

SYNOPSIS

sysctl [-bdeFhilNnotqWx] [-B bufsize] [-f filename] name[=value[,value]] ...

sysctl [-bdeFhlNnotqWx] [-B bufsize] -a

DESCRIPTION

The sysctl utility retrieves kernel state and allows processes with appropriate privilege to set kernel state. The state to be retrieved or set is described using a “Management Information Base” (“MIB”) style name, described as a dotted set of components.

The following options are available:

-A

Equivalent to -o -a (for compatibility).

-a

List all the currently available values except for those which are opaque or excluded from listing via the CTLFLAG_SKIP flag. This option is ignored if one or more variable names are specified on the command line.

-b

Force the value of the variable(s) to be output in raw, binary format. No names are printed and no terminating newlines are output. This is mostly useful with a single variable.

-B bufsize

Set the buffer size to read from the sysctl to bufsize. This is necessary for a sysctl that has variable length, and the probe value of 0 is a valid length.

-d

Print the description of the variable instead of its value.

-e

Separate the name and the value of the variable(s) with ‘=’. This is useful for producing output which can be fed back to the sysctl utility. This option is ignored if either -N or -n is specified, or a variable is being set.

-f filename

Specify a file which contains a pair of name and value in each line. sysctl reads and processes the specified file first and then processes the name and value pairs in the command line argument.

-F

Print the format of the variable. This is additional information to describe the type of the variable and most useful with struct types such as clockinfo, timeval, and loadavg.

-h

Format output for human, rather than machine, readability.

-i

Ignore unknown OIDs. The purpose is to make use of sysctl for collecting data from a variety of machines (not all of which are necessarily running exactly the same software) easier.

-l

Show the length of variables along with their values. This option cannot be combined with the -N option.

-N

Show only variable names, not their values. This is particularly useful with shells that offer programmable completion. To enable completion of variable names in zsh(1) (ports/shells/zsh), use the following code:

listsysctls () { set -A reply $(sysctl -AN ${1%.*}) }
compctl -K listsysctls sysctl

To enable completion of variable names in tcsh(1), use:

complete sysctl 'n/*/`sysctl -Na`/'

-n

Do not show variable names. This option is useful for setting shell variables. For instance, to save the pagesize in variable psize, use:

set psize=`sysctl -n hw.pagesize`

-o

Show opaque variables (which are normally suppressed). The format and length are printed, as well as a hex dump of the first sixteen bytes of the value.

-q

Suppress some warnings generated by sysctl to standard error.

-t

Print the type of the variable.

-W

Display only writable variables. Useful for determining the set of runtime tunable sysctls.

-X

Equivalent to -x -a (for compatibility).

-x

As -o, but prints a hex dump of the entire value instead of just the first few bytes.

The information available from sysctl consists of integers, strings, and opaque types. The sysctl utility only knows about a couple of opaque types, and will resort to hexdumps for the rest. The opaque information is much more useful if retrieved by special purpose programs such as ps(1), systat(1), and netstat(1).

The string and integer information is summarized below. For a detailed description of these variables see sysctl(3).

The changeable column indicates whether a process with appropriate privilege can change the value. String and integer values can be set using sysctl.

NameTypeChangeable
hw.activecpuintegerno
hw.busfrequencyintegerno
hw.busfrequency_maxintegerno
hw.busfrequency_minintegerno
hw.byteorderintegerno
hw.cacheconfigstructno
hw.cachelinesizeintegerno
hw.cachesizestructno
hw.cpu64bit_capableintegerno
hw.cpufamilyintegerno
hw.cpufrequencyintegerno
hw.cpufrequency_maxintegerno
hw.cpufrequency_minintegerno
hw.cpusubtypeintegerno
hw.cputhreadtypeintegerno
hw.cputypeintegerno
hw.l1dcachesizeintegerno
hw.l1icachesizeintegerno
hw.l2cachesizeintegerno
hw.l3cachesizeintegerno
hw.logicalcpuintegerno
hw.logicalcpu_maxintegerno
hw.memsizeintegerno
hw.ncpuintegerno
hw.packagesintegerno
hw.pagesizeintegerno
hw.physicalcpuintegerno
hw.physicalcpu_maxintegerno
hw.tbfrequencyintegerno
kern.argmaxintegerno
kern.bootargsstringno
kern.boottimestructno
kern.clockratestructno
kern.coredumpintegeryes
kern.corefilestringyes
kern.flush_cache_on_writeintegeryes
kern.hostidintegeryes
kern.hostnamestringyes
kern.job_controlintegerno
kern.maxfilesintegeryes
kern.maxfilesperprocintegeryes
kern.maxnbufintegeryes
kern.maxprocintegeryes
kern.maxprocperuidintegeryes
kern.maxvnodesintegeryes
kern.msgbufintegeryes
kern.nbufintegerno
kern.netbootintegerno
kern.ngroupsintegerno
kern.nisdomainnamestringyes
kern.num_filesintegerno
kern.num_tasksintegerno
kern.num_taskthreadsintegerno
kern.num_threadsintegerno
kern.num_vnodesintegerno
kern.nxintegeryes
kern.osreleasestringno
kern.osrevisionintegerno
kern.ostypestringno
kern.osversionstringyes
kern.posix1versionintegerno
kern.procnamestringyes
kern.safebootintegerno
kern.saved_idsintegerno
kern.secure_kernelintegerno
kern.securelevelintegeryes
kern.singleuserintegerno
kern.sleeptimestructno
kern.slideintegerno
kern.stack_depth_maxintegerno
kern.stack_sizeintegerno
kern.sugid_coredumpintegeryes
kern.sugid_scriptsintegeryes
kern.symfilestringno
kern.usrstackintegerno
kern.usrstack64integerno
kern.uuidstringno
kern.versionstringno
kern.waketimestructno
machdep.cpu.address_bits.physicalintegerno
machdep.cpu.address_bits.virtualintegerno
machdep.cpu.brandintegerno
machdep.cpu.brand_stringstringno
machdep.cpu.cache.L2_associativityintegerno
machdep.cpu.cache.linesizeintegerno
machdep.cpu.cache.sizeintegerno
machdep.cpu.core_countintegerno
machdep.cpu.cores_per_packageintegerno
machdep.cpu.extfamilyintegerno
machdep.cpu.extfeature_bitsintegerno
machdep.cpu.extfeaturesstringno
machdep.cpu.extmodelintegerno
machdep.cpu.familyintegerno
machdep.cpu.feature_bitsintegerno
machdep.cpu.featuresstringno
machdep.cpu.leaf7_feature_bitsintegerno
machdep.cpu.leaf7_featuresstringno
machdep.cpu.logical_per_packageintegerno
machdep.cpu.max_basicintegerno
machdep.cpu.max_extintegerno
machdep.cpu.microcode_versionintegerno
machdep.cpu.modelintegerno
machdep.cpu.processor_flagintegerno
machdep.cpu.signatureintegerno
machdep.cpu.steppingintegerno
machdep.cpu.thread_countintegerno
machdep.cpu.tlb.data.largeintegerno
machdep.cpu.tlb.data.large_level1integerno
machdep.cpu.tlb.data.smallintegerno
machdep.cpu.tlb.data.small_level1integerno
machdep.cpu.tlb.inst.largeintegerno
machdep.cpu.tlb.inst.smallintegerno
machdep.cpu.tlb.sharedintegerno
machdep.cpu.ucupdateintegeryes
machdep.cpu.vendorstringno
machdep.cpu.xsave.extended_stateintegerno
machdep.tsc.deep_idle_rebaseintegeryes
machdep.tsc.frequencyintegerno
machdep.tsc.nanotime.generationintegerno
machdep.tsc.nanotime.shiftintegerno
net.inet.ip.forwardingintegeryes
net.inet.ip.portrange.firstintegeryes
net.inet.ip.portrange.hifirstintegeryes
net.inet.ip.portrange.hilastintegeryes
net.inet.ip.portrange.lastintegeryes
net.inet.ip.portrange.lowfirstintegeryes
net.inet.ip.portrange.lowlastintegeryes
net.inet.ip.redirectintegeryes
net.inet.ip.ttlintegeryes
net.inet.udp.checksumintegeryes
net.inet.udp.maxdgramintegeryes
vm.loadavgstructno
vm.swapusagestructno
user.bc_base_maxintegerno
user.bc_dim_maxintegerno
user.bc_scale_maxintegerno
user.bc_string_maxintegerno
user.coll_weights_maxintegerno
user.cs_pathstringno
user.expr_nest_maxintegerno
user.line_maxintegerno
user.posix2_c_bindintegerno
user.posix2_c_devintegerno
user.posix2_char_termintegerno
user.posix2_fort_devintegerno
user.posix2_fort_runintegerno
user.posix2_localedefintegerno
user.posix2_sw_devintegerno
user.posix2_upeintegerno
user.posix2_versionintegerno
user.re_dup_maxintegerno
user.stream_maxintegerno
user.tzname_maxintegerno

Note that the hw.ncpu attribute is deprecated, and one of the more specific MIBs, hw.logicalcpu, hw.logicalcpu_max, hw.physicalcpu, or hw.physicalcpu_max, should be used instead.

FILES

In sys/sysctl.h

definitions for top level identifiers, second level kernel and hardware identifiers, and user level identifiers

In sys/socket.h

definitions for second level network identifiers

In sys/gmon.h

definitions for third level profiling identifiers

In vm/vm_param.h

definitions for second level virtual memory identifiers

In netinet/in.h

definitions for third level Internet identifiers and fourth level IP identifiers

In netinet/icmp_var.h

definitions for fourth level ICMP identifiers

In netinet/udp_var.h

definitions for fourth level UDP identifiers

EXIT STATUS

The sysctl utility exits 0 on success, and >0 if an error occurs.

EXAMPLES

For example, to retrieve the maximum number of processes allowed in the system, one would use the following request:

sysctl kern.maxproc

To set the maximum number of processes allowed per uid to 1000, one would use the following request:

sysctl kern.maxprocperuid=1000

Information about the system clock rate may be obtained with:

sysctl kern.clockrate

Information about the load average history may be obtained with:

sysctl vm.loadavg

More variables than these exist, and the best and likely only place to search for their deeper meaning is undoubtedly the source where they are defined.

COMPATIBILITY

The -w option has been deprecated and is silently ignored.

SEE ALSO

sysctl(3), sysctl.conf(5)

HISTORY

A sysctl utility first appeared in 4.4BSD.

In FreeBSD 2.2, sysctl was significantly remodeled.

History

-A since Mac OS X 10.3; -B since macOS 14.4; -F since macOS 14.4; -N since OS X 10.10; -W since macOS 14.4; -X since Mac OS X 10.3; -a since Mac OS X 10.3; -b since Mac OS X 10.3; -d since OS X 10.10; -e since OS X 10.10; -f since macOS 14.4; -h since OS X 10.10; -i since OS X 10.10; -l since macOS 14.4; -n since Mac OS X 10.3; -o since OS X 10.10; -q since OS X 10.10; -t since macOS 14.4; -x since OS X 10.10.

-w until OS X 10.9.5.