1.\" Copyright (c) 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.\" From: @(#)sysctl.8 8.1 (Berkeley) 6/6/93 29.\" $FreeBSD$ 30.\" 31.Dd December 24, 2022 32.Dt SYSCTL 8 33.Os 34.Sh NAME 35.Nm sysctl 36.Nd get or set kernel state 37.Sh SYNOPSIS 38.Nm 39.Op Fl bdeFhilNnoTtqWx 40.Op Fl B Ar bufsize 41.Op Fl f Ar filename 42.Ar name Ns Op = Ns Ar value Ns Op , Ns Ar value 43.Ar ... 44.Nm 45.Op Fl bdeFhlNnoTtqWx 46.Op Fl B Ar bufsize 47.Fl a 48.Sh DESCRIPTION 49The 50.Nm 51utility retrieves kernel state and allows processes with appropriate 52privilege to set kernel state. 53The state to be retrieved or set is described using a 54.Dq Management Information Base 55.Pq Dq MIB 56style name, described as a dotted set of 57components. 58.Pp 59The following options are available: 60.Bl -tag -width indent 61.It Fl A 62Equivalent to 63.Fl o a 64(for compatibility). 65.It Fl a 66List all the currently available values except for those which are 67opaque or excluded from listing via the 68.Dv CTLFLAG_SKIP 69flag. 70This option is ignored if one or more variable names are specified on 71the command line. 72.It Fl b 73Force the value of the variable(s) to be output in raw, binary format. 74No names are printed and no terminating newlines are output. 75This is mostly useful with a single variable. 76.It Fl B Ar bufsize 77Set the buffer size to read from the 78.Nm 79to 80.Ar bufsize . 81This is necessary for a 82.Nm 83that has variable length, and the probe value of 0 is a valid length, such as 84.Va kern.arandom . 85.It Fl d 86Print the description of the variable instead of its value. 87.It Fl e 88Separate the name and the value of the variable(s) with 89.Ql = . 90This is useful for producing output which can be fed back to the 91.Nm 92utility. 93This option is ignored if either 94.Fl N 95or 96.Fl n 97is specified, or a variable is being set. 98.It Fl f Ar filename 99Specify a file which contains a pair of name and value in each line. 100.Nm 101reads and processes the specified file first and then processes the name 102and value pairs in the command line argument. 103.It Fl F 104Print the format of the variable. 105This is additional information to describe the type of the variable and 106most useful with struct types such as clockinfo, timeval, and loadavg. 107.It Fl h 108Format output for human, rather than machine, readability. 109.It Fl i 110Ignore unknown OIDs. 111The purpose is to make use of 112.Nm 113for collecting data from a variety of machines (not all of which 114are necessarily running exactly the same software) easier. 115.It Fl l 116Show the length of variables along with their values. 117This option cannot be combined with the 118.Fl N 119option. 120.It Fl N 121Show only variable names, not their values. 122This is particularly useful with shells that offer programmable 123completion. 124To enable completion of variable names in 125.Xr zsh 1 Pq Pa ports/shells/zsh , 126use the following code: 127.Bd -literal -offset indent 128listsysctls () { set -A reply $(sysctl -AN ${1%.*}) } 129compctl -K listsysctls sysctl 130.Ed 131.Pp 132To enable completion of variable names in 133.Xr tcsh 1 , 134use: 135.Pp 136.Dl "complete sysctl 'n/*/`sysctl -Na`/'" 137.It Fl n 138Do not show variable names. 139This option is useful for setting shell variables. 140For instance, to save the pagesize in variable 141.Va psize , 142use: 143.Pp 144.Dl "set psize=`sysctl -n hw.pagesize`" 145.It Fl o 146Show opaque variables (which are normally suppressed). 147The format and length are printed, as well as a hex dump of the first 148sixteen bytes of the value. 149.It Fl q 150Suppress some warnings generated by 151.Nm 152to standard error. 153.It Fl T 154Display only variables that are settable via loader (CTLFLAG_TUN). 155.It Fl t 156Print the type of the variable. 157.It Fl W 158Display only writable variables that are not statistical. 159Useful for determining the set of runtime tunable sysctls. 160.It Fl X 161Equivalent to 162.Fl x a 163(for compatibility). 164.It Fl x 165As 166.Fl o , 167but prints a hex dump of the entire value instead of just the first 168few bytes. 169.El 170.Pp 171The information available from 172.Nm 173consists of integers, strings, and opaque types. 174The 175.Nm 176utility 177only knows about a couple of opaque types, and will resort to hexdumps 178for the rest. 179The opaque information is much more useful if retrieved by special 180purpose programs such as 181.Xr ps 1 , 182.Xr systat 1 , 183and 184.Xr netstat 1 . 185.Pp 186Some of the variables which cannot be modified during normal system 187operation can be initialized via 188.Xr loader 8 189tunables. 190This can for example be done by setting them in 191.Xr loader.conf 5 . 192Please refer to 193.Xr loader.conf 5 194for more information on which tunables are available and how to set them. 195.Pp 196The string and integer information is summarized below. 197For a detailed description of these variables see 198.Xr sysctl 3 . 199.Pp 200The changeable column indicates whether a process with appropriate 201privilege can change the value. 202String and integer values can be set using 203.Nm . 204.Bl -column security.bsd.unprivileged_read_msgbuf integerxxx 205.It Sy "Name Type Changeable" 206.It "kern.ostype string no" 207.It "kern.osrelease string no" 208.It "kern.osrevision integer no" 209.It "kern.version string no" 210.It "kern.maxvnodes integer yes" 211.It "kern.maxproc integer no" 212.It "kern.maxprocperuid integer yes" 213.It "kern.maxfiles integer yes" 214.It "kern.maxfilesperproc integer yes" 215.It "kern.argmax integer no" 216.It "kern.securelevel integer raise only" 217.It "kern.hostname string yes" 218.It "kern.hostid integer yes" 219.It "kern.clockrate struct no" 220.It "kern.posix1version integer no" 221.It "kern.ngroups integer no" 222.It "kern.job_control integer no" 223.It "kern.saved_ids integer no" 224.It "kern.boottime struct no" 225.It "kern.domainname string yes" 226.It "kern.filedelay integer yes" 227.It "kern.dirdelay integer yes" 228.It "kern.metadelay integer yes" 229.It "kern.osreldate integer no" 230.It "kern.bootfile string yes" 231.It "kern.corefile string yes" 232.It "kern.logsigexit integer yes" 233.It "security.bsd.suser_enabled integer yes" 234.It "security.bsd.see_other_uids integer yes" 235.It "security.bsd.unprivileged_proc_debug integer yes" 236.It "security.bsd.unprivileged_read_msgbuf integer yes" 237.It "vm.loadavg struct no" 238.It "hw.machine string no" 239.It "hw.model string no" 240.It "hw.ncpu integer no" 241.It "hw.byteorder integer no" 242.It "hw.physmem integer no" 243.It "hw.usermem integer no" 244.It "hw.pagesize integer no" 245.It "hw.floatingpoint integer no" 246.It "hw.machine_arch string no" 247.It "hw.realmem integer no" 248.It "machdep.adjkerntz integer yes" 249.It "machdep.disable_rtc_set integer yes" 250.It "machdep.guessed_bootdev string no" 251.It "user.cs_path string no" 252.It "user.bc_base_max integer no" 253.It "user.bc_dim_max integer no" 254.It "user.bc_scale_max integer no" 255.It "user.bc_string_max integer no" 256.It "user.coll_weights_max integer no" 257.It "user.expr_nest_max integer no" 258.It "user.line_max integer no" 259.It "user.re_dup_max integer no" 260.It "user.posix2_version integer no" 261.It "user.posix2_c_bind integer no" 262.It "user.posix2_c_dev integer no" 263.It "user.posix2_char_term integer no" 264.It "user.posix2_fort_dev integer no" 265.It "user.posix2_fort_run integer no" 266.It "user.posix2_localedef integer no" 267.It "user.posix2_sw_dev integer no" 268.It "user.posix2_upe integer no" 269.It "user.stream_max integer no" 270.It "user.tzname_max integer no" 271.It "user.localbase string no" 272.El 273.Sh FILES 274.Bl -tag -width ".In netinet/icmp_var.h" -compact 275.It In sys/sysctl.h 276definitions for top level identifiers, second level kernel and hardware 277identifiers, and user level identifiers 278.It In sys/socket.h 279definitions for second level network identifiers 280.It In sys/gmon.h 281definitions for third level profiling identifiers 282.It In vm/vm_param.h 283definitions for second level virtual memory identifiers 284.It In netinet/in.h 285definitions for third level Internet identifiers and 286fourth level IP identifiers 287.It In netinet/icmp_var.h 288definitions for fourth level ICMP identifiers 289.It In netinet/udp_var.h 290definitions for fourth level UDP identifiers 291.El 292.Sh EXIT STATUS 293.Ex -std 294.Sh EXAMPLES 295For example, to retrieve the maximum number of processes allowed 296in the system, one would use the following request: 297.Pp 298.Dl "sysctl kern.maxproc" 299.Pp 300To set the maximum number of processes allowed 301per uid to 1000, one would use the following request: 302.Pp 303.Dl "sysctl kern.maxprocperuid=1000" 304.Pp 305Information about the system clock rate may be obtained with: 306.Pp 307.Dl "sysctl kern.clockrate" 308.Pp 309Information about the load average history may be obtained with: 310.Pp 311.Dl "sysctl vm.loadavg" 312.Pp 313More variables than these exist, and the best and likely only place 314to search for their deeper meaning is undoubtedly the source where 315they are defined. 316.Sh COMPATIBILITY 317The 318.Fl w 319option has been deprecated and is silently ignored. 320.Sh SEE ALSO 321.Xr sysctl 3 , 322.Xr loader.conf 5 , 323.Xr sysctl.conf 5 , 324.Xr loader 8 325.Sh HISTORY 326A 327.Nm 328utility first appeared in 329.Bx 4.4 . 330.Pp 331In 332.Fx 2.2 , 333.Nm 334was significantly remodeled. 335.Sh BUGS 336The 337.Nm 338utility presently exploits an undocumented interface to the kernel 339.Xr sysctl 9 340facility to traverse the sysctl tree and to retrieve format 341and name information. 342This correct interface is being thought about for the time being. 343