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