xref: /freebsd/sbin/sysctl/sysctl.8 (revision 40a8ac8f62b535d30349faf28cf47106b7041b83)
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.\" 4. 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 13, 2012
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 bdehiNnoRTqx
40.Op Fl f Ar filename
41.Ar name Ns Op = Ns Ar value
42.Ar ...
43.Nm
44.Op Fl bdehNnoRTqx
45.Fl a
46.Sh DESCRIPTION
47The
48.Nm
49utility retrieves kernel state and allows processes with appropriate
50privilege to set kernel state.
51The state to be retrieved or set is described using a
52.Dq Management Information Base
53.Pq Dq MIB
54style name, described as a dotted set of
55components.
56.Pp
57The following options are available:
58.Bl -tag -width indent
59.It Fl A
60Equivalent to
61.Fl o a
62(for compatibility).
63.It Fl a
64List all the currently available non-opaque values.
65This option is ignored if one or more variable names are specified on
66the command line.
67.It Fl b
68Force the value of the variable(s) to be output in raw, binary format.
69No names are printed and no terminating newlines are output.
70This is mostly useful with a single variable.
71.It Fl d
72Print the description of the variable instead of its value.
73.It Fl e
74Separate the name and the value of the variable(s) with
75.Ql = .
76This is useful for producing output which can be fed back to the
77.Nm
78utility.
79This option is ignored if either
80.Fl N
81or
82.Fl n
83is specified, or a variable is being set.
84.It Fl f Ar filename
85Specify a file which contains a pair of name and value in each line.
86.Nm
87reads and processes the specified file first and then processes the name
88and value pairs in the command line argument.
89.It Fl h
90Format output for human, rather than machine, readability.
91.It Fl i
92Ignore unknown OIDs.
93The purpose is to make use of
94.Nm
95for collecting data from a variety of machines (not all of which
96are necessarily running exactly the same software) easier.
97.It Fl N
98Show only variable names, not their values.
99This is particularly useful with shells that offer programmable
100completion.
101To enable completion of variable names in
102.Xr zsh 1 Pq Pa ports/shells/zsh ,
103use the following code:
104.Bd -literal -offset indent
105listsysctls () { set -A reply $(sysctl -AN ${1%.*}) }
106compctl -K listsysctls sysctl
107.Ed
108.Pp
109To enable completion of variable names in
110.Xr tcsh 1 ,
111use:
112.Pp
113.Dl "complete sysctl 'n/*/`sysctl -Na`/'"
114.It Fl n
115Show only variable values, not their names.
116This option is useful for setting shell variables.
117For instance, to save the pagesize in variable
118.Va psize ,
119use:
120.Pp
121.Dl "set psize=`sysctl -n hw.pagesize`"
122.It Fl o
123Show opaque variables (which are normally suppressed).
124The format and length are printed, as well as a hex dump of the first
125sixteen bytes of the value.
126.It Fl q
127Suppress some warnings generated by
128.Nm
129to standard error.
130.It Fl T
131Display only variables that are setable via loader (CTLFLAG_TUN).
132.It Fl W
133Display only writable variables that are not statistical.
134Useful for determining the set of runtime tunable sysctls.
135.It Fl X
136Equivalent to
137.Fl x a
138(for compatibility).
139.It Fl x
140As
141.Fl o ,
142but prints a hex dump of the entire value instead of just the first
143few bytes.
144.El
145.Pp
146The information available from
147.Nm
148consists of integers, strings, and opaque types.
149The
150.Nm
151utility
152only knows about a couple of opaque types, and will resort to hexdumps
153for the rest.
154The opaque information is much more useful if retrieved by special
155purpose programs such as
156.Xr ps 1 ,
157.Xr systat 1 ,
158and
159.Xr netstat 1 .
160.Pp
161Some of the variables which cannot be modified during normal system
162operation can be initialized via
163.Xr loader 8
164tunables.
165This can for example be done by setting them in
166.Xr loader.conf 5 .
167Please refer to
168.Xr loader.conf 5
169for more information on which tunables are available and how to set them.
170.Pp
171The string and integer information is summarized below.
172For a detailed description of these variable see
173.Xr sysctl 3 .
174.Pp
175The changeable column indicates whether a process with appropriate
176privilege can change the value.
177String and integer values can be set using
178.Nm .
179.Bl -column security.bsd.unprivileged_read_msgbuf integerxxx
180.It Sy "Name	Type	Changeable"
181.It "kern.ostype	string	no"
182.It "kern.osrelease	string	no"
183.It "kern.osrevision	integer	no"
184.It "kern.version	string	no"
185.It "kern.maxvnodes	integer	yes"
186.It "kern.maxproc	integer	no"
187.It "kern.maxprocperuid	integer	yes"
188.It "kern.maxfiles	integer	yes"
189.It "kern.maxfilesperproc	integer	yes"
190.It "kern.argmax	integer	no"
191.It "kern.securelevel	integer	raise only"
192.It "kern.hostname	string	yes"
193.It "kern.hostid	integer	yes"
194.It "kern.clockrate	struct	no"
195.It "kern.posix1version	integer	no"
196.It "kern.ngroups	integer	no"
197.It "kern.job_control	integer	no"
198.It "kern.saved_ids	integer	no"
199.It "kern.boottime	struct	no"
200.It "kern.domainname	string	yes"
201.It "kern.filedelay	integer	yes"
202.It "kern.dirdelay	integer	yes"
203.It "kern.metadelay	integer	yes"
204.It "kern.osreldate	string	no"
205.It "kern.bootfile	string	yes"
206.It "kern.corefile	string	yes"
207.It "kern.logsigexit	integer	yes"
208.It "security.bsd.suser_enabled	integer	yes"
209.It "security.bsd.see_other_uids	integer	yes"
210.It "security.bsd.unprivileged_proc_debug	integer	yes"
211.It "security.bsd.unprivileged_read_msgbuf	integer	yes"
212.It "vm.loadavg	struct	no"
213.It "hw.machine	string	no"
214.It "hw.model	string	no"
215.It "hw.ncpu	integer	no"
216.It "hw.byteorder	integer	no"
217.It "hw.physmem	integer	no"
218.It "hw.usermem	integer	no"
219.It "hw.pagesize	integer	no"
220.It "hw.floatingpoint	integer	no"
221.It "hw.machine_arch	string	no"
222.It "hw.realmem	integer	no"
223.It "machdep.adjkerntz	integer	yes"
224.It "machdep.disable_rtc_set	integer	yes"
225.It "machdep.guessed_bootdev	string	no"
226.It "user.cs_path	string	no"
227.It "user.bc_base_max	integer	no"
228.It "user.bc_dim_max	integer	no"
229.It "user.bc_scale_max	integer	no"
230.It "user.bc_string_max	integer	no"
231.It "user.coll_weights_max	integer	no"
232.It "user.expr_nest_max	integer	no"
233.It "user.line_max	integer	no"
234.It "user.re_dup_max	integer	no"
235.It "user.posix2_version	integer	no"
236.It "user.posix2_c_bind	integer	no"
237.It "user.posix2_c_dev	integer	no"
238.It "user.posix2_char_term	integer	no"
239.It "user.posix2_fort_dev	integer	no"
240.It "user.posix2_fort_run	integer	no"
241.It "user.posix2_localedef	integer	no"
242.It "user.posix2_sw_dev	integer	no"
243.It "user.posix2_upe	integer	no"
244.It "user.stream_max	integer	no"
245.It "user.tzname_max	integer	no"
246.El
247.Sh FILES
248.Bl -tag -width ".In netinet/icmp_var.h" -compact
249.It In sys/sysctl.h
250definitions for top level identifiers, second level kernel and hardware
251identifiers, and user level identifiers
252.It In sys/socket.h
253definitions for second level network identifiers
254.It In sys/gmon.h
255definitions for third level profiling identifiers
256.It In vm/vm_param.h
257definitions for second level virtual memory identifiers
258.It In netinet/in.h
259definitions for third level Internet identifiers and
260fourth level IP identifiers
261.It In netinet/icmp_var.h
262definitions for fourth level ICMP identifiers
263.It In netinet/udp_var.h
264definitions for fourth level UDP identifiers
265.El
266.Sh EXAMPLES
267For example, to retrieve the maximum number of processes allowed
268in the system, one would use the following request:
269.Pp
270.Dl "sysctl kern.maxproc"
271.Pp
272To set the maximum number of processes allowed
273per uid to 1000, one would use the following request:
274.Pp
275.Dl "sysctl kern.maxprocperuid=1000"
276.Pp
277Information about the system clock rate may be obtained with:
278.Pp
279.Dl "sysctl kern.clockrate"
280.Pp
281Information about the load average history may be obtained with:
282.Pp
283.Dl "sysctl vm.loadavg"
284.Pp
285More variables than these exist, and the best and likely only place
286to search for their deeper meaning is undoubtedly the source where
287they are defined.
288.Sh COMPATIBILITY
289The
290.Fl w
291option has been deprecated and is silently ignored.
292.Sh SEE ALSO
293.Xr sysctl 3 ,
294.Xr loader.conf 5 ,
295.Xr sysctl.conf 5 ,
296.Xr loader 8
297.Sh HISTORY
298A
299.Nm
300utility first appeared in
301.Bx 4.4 .
302.Pp
303In
304.Fx 2.2 ,
305.Nm
306was significantly remodeled.
307.Sh BUGS
308The
309.Nm
310utility presently exploits an undocumented interface to the kernel
311sysctl facility to traverse the sysctl tree and to retrieve format
312and name information.
313This correct interface is being thought about for the time being.
314