xref: /freebsd/lib/libc/gen/sysctl.3 (revision 5dae51da3da0cc94d17bd67b308fad304ebec7e0)
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.\"	@(#)sysctl.3	8.4 (Berkeley) 5/9/95
29.\" $FreeBSD$
30.\"
31.Dd September 10, 2015
32.Dt SYSCTL 3
33.Os
34.Sh NAME
35.Nm sysctl ,
36.Nm sysctlbyname ,
37.Nm sysctlnametomib
38.Nd get or set system information
39.Sh LIBRARY
40.Lb libc
41.Sh SYNOPSIS
42.In sys/types.h
43.In sys/sysctl.h
44.Ft int
45.Fn sysctl "const int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "const void *newp" "size_t newlen"
46.Ft int
47.Fn sysctlbyname "const char *name" "void *oldp" "size_t *oldlenp" "const void *newp" "size_t newlen"
48.Ft int
49.Fn sysctlnametomib "const char *name" "int *mibp" "size_t *sizep"
50.Sh DESCRIPTION
51The
52.Fn sysctl
53function retrieves system information and allows processes with
54appropriate privileges to set system information.
55The information available from
56.Fn sysctl
57consists of integers, strings, and tables.
58Information may be retrieved and set from the command interface
59using the
60.Xr sysctl 8
61utility.
62.Pp
63Unless explicitly noted below,
64.Fn sysctl
65returns a consistent snapshot of the data requested.
66Consistency is obtained by locking the destination
67buffer into memory so that the data may be copied out without blocking.
68Calls to
69.Fn sysctl
70are serialized to avoid deadlock.
71.Pp
72The state is described using a ``Management Information Base'' (MIB)
73style name, listed in
74.Fa name ,
75which is a
76.Fa namelen
77length array of integers.
78.Pp
79The
80.Fn sysctlbyname
81function accepts an ASCII representation of the name and internally
82looks up the integer name vector.
83Apart from that, it behaves the same
84as the standard
85.Fn sysctl
86function.
87.Pp
88The information is copied into the buffer specified by
89.Fa oldp .
90The size of the buffer is given by the location specified by
91.Fa oldlenp
92before the call,
93and that location gives the amount of data copied after a successful call
94and after a call that returns with the error code
95.Er ENOMEM .
96If the amount of data available is greater
97than the size of the buffer supplied,
98the call supplies as much data as fits in the buffer provided
99and returns with the error code
100.Er ENOMEM .
101If the old value is not desired,
102.Fa oldp
103and
104.Fa oldlenp
105should be set to NULL.
106.Pp
107The size of the available data can be determined by calling
108.Fn sysctl
109with the
110.Dv NULL
111argument for
112.Fa oldp .
113The size of the available data will be returned in the location pointed to by
114.Fa oldlenp .
115For some operations, the amount of space may change often.
116For these operations,
117the system attempts to round up so that the returned size is
118large enough for a call to return the data shortly thereafter.
119.Pp
120To set a new value,
121.Fa newp
122is set to point to a buffer of length
123.Fa newlen
124from which the requested value is to be taken.
125If a new value is not to be set,
126.Fa newp
127should be set to NULL and
128.Fa newlen
129set to 0.
130.Pp
131The
132.Fn sysctlnametomib
133function accepts an ASCII representation of the name,
134looks up the integer name vector,
135and returns the numeric representation in the mib array pointed to by
136.Fa mibp .
137The number of elements in the mib array is given by the location specified by
138.Fa sizep
139before the call,
140and that location gives the number of entries copied after a successful call.
141The resulting
142.Fa mib
143and
144.Fa size
145may be used in subsequent
146.Fn sysctl
147calls to get the data associated with the requested ASCII name.
148This interface is intended for use by applications that want to
149repeatedly request the same variable (the
150.Fn sysctl
151function runs in about a third the time as the same request made via the
152.Fn sysctlbyname
153function).
154The
155.Fn sysctlnametomib
156function is also useful for fetching mib prefixes and then adding
157a final component.
158For example, to fetch process information
159for processes with pid's less than 100:
160.Pp
161.Bd -literal -offset indent -compact
162int i, mib[4];
163size_t len;
164struct kinfo_proc kp;
165
166/* Fill out the first three components of the mib */
167len = 4;
168sysctlnametomib("kern.proc.pid", mib, &len);
169
170/* Fetch and print entries for pid's < 100 */
171for (i = 0; i < 100; i++) {
172	mib[3] = i;
173	len = sizeof(kp);
174	if (sysctl(mib, 4, &kp, &len, NULL, 0) == -1)
175		perror("sysctl");
176	else if (len > 0)
177		printkproc(&kp);
178}
179.Ed
180.Pp
181The top level names are defined with a CTL_ prefix in
182.In sys/sysctl.h ,
183and are as follows.
184The next and subsequent levels down are found in the include files
185listed here, and described in separate sections below.
186.Bl -column CTLXMACHDEPXXX "Next Level NamesXXXXXX" -offset indent
187.It Sy Name Ta Sy Next Level Names Ta Sy Description
188.It Dv CTL_DEBUG Ta In sys/sysctl.h Ta Debugging
189.It Dv CTL_VFS Ta In sys/mount.h Ta File system
190.It Dv CTL_HW Ta In sys/sysctl.h Ta Generic CPU, I/O
191.It Dv CTL_KERN Ta In sys/sysctl.h Ta High kernel limits
192.It Dv CTL_MACHDEP Ta In sys/sysctl.h Ta Machine dependent
193.It Dv CTL_NET Ta In sys/socket.h Ta Networking
194.It Dv CTL_USER Ta In sys/sysctl.h Ta User-level
195.It Dv CTL_VM Ta In vm/vm_param.h Ta Virtual memory
196.El
197.Pp
198For example, the following retrieves the maximum number of processes allowed
199in the system:
200.Pp
201.Bd -literal -offset indent -compact
202int mib[2], maxproc;
203size_t len;
204
205mib[0] = CTL_KERN;
206mib[1] = KERN_MAXPROC;
207len = sizeof(maxproc);
208sysctl(mib, 2, &maxproc, &len, NULL, 0);
209.Ed
210.Pp
211To retrieve the standard search path for the system utilities:
212.Pp
213.Bd -literal -offset indent -compact
214int mib[2];
215size_t len;
216char *p;
217
218mib[0] = CTL_USER;
219mib[1] = USER_CS_PATH;
220sysctl(mib, 2, NULL, &len, NULL, 0);
221p = malloc(len);
222sysctl(mib, 2, p, &len, NULL, 0);
223.Ed
224.Ss CTL_DEBUG
225The debugging variables vary from system to system.
226A debugging variable may be added or deleted without need to recompile
227.Fn sysctl
228to know about it.
229Each time it runs,
230.Fn sysctl
231gets the list of debugging variables from the kernel and
232displays their current values.
233The system defines twenty
234.Pq Vt "struct ctldebug"
235variables named
236.Va debug0
237through
238.Va debug19 .
239They are declared as separate variables so that they can be
240individually initialized at the location of their associated variable.
241The loader prevents multiple use of the same variable by issuing errors
242if a variable is initialized in more than one place.
243For example, to export the variable
244.Va dospecialcheck
245as a debugging variable, the following declaration would be used:
246.Pp
247.Bd -literal -offset indent -compact
248int dospecialcheck = 1;
249struct ctldebug debug5 = { "dospecialcheck", &dospecialcheck };
250.Ed
251.Ss CTL_VFS
252A distinguished second level name, VFS_GENERIC,
253is used to get general information about all file systems.
254One of its third level identifiers is VFS_MAXTYPENUM
255that gives the highest valid file system type number.
256Its other third level identifier is VFS_CONF that
257returns configuration information about the file system
258type given as a fourth level identifier (see
259.Xr getvfsbyname 3
260as an example of its use).
261The remaining second level identifiers are the
262file system type number returned by a
263.Xr statfs 2
264call or from VFS_CONF.
265The third level identifiers available for each file system
266are given in the header file that defines the mount
267argument structure for that file system.
268.Ss CTL_HW
269The string and integer information available for the CTL_HW level
270is detailed below.
271The changeable column shows whether a process with appropriate
272privilege may change the value.
273.Bl -column "Second Level Name" integerXXX Changeable -offset indent
274.It Sy Second Level Name Ta Sy Type Ta Sy Changeable
275.It Dv HW_MACHINE Ta string Ta no
276.It Dv HW_MODEL Ta string Ta no
277.It Dv HW_NCPU Ta integer Ta no
278.It Dv HW_BYTEORDER Ta integer Ta no
279.It Dv HW_PHYSMEM Ta integer Ta no
280.It Dv HW_USERMEM Ta integer Ta no
281.It Dv HW_PAGESIZE Ta integer Ta no
282.\".It Dv HW_DISKNAMES Ta integer Ta no
283.\".It Dv HW_DISKSTATS Ta integer Ta no
284.It Dv HW_FLOATINGPT Ta integer Ta no
285.It Dv HW_MACHINE_ARCH Ta string Ta no
286.It Dv HW_REALMEM Ta integer Ta no
287.El
288.Bl -tag -width 6n
289.It Li HW_MACHINE
290The machine class.
291.It Li HW_MODEL
292The machine model
293.It Li HW_NCPU
294The number of cpus.
295.It Li HW_BYTEORDER
296The byteorder (4321 or 1234).
297.It Li HW_PHYSMEM
298The bytes of physical memory.
299.It Li HW_USERMEM
300The bytes of non-kernel memory.
301.It Li HW_PAGESIZE
302The software page size.
303.\".It Fa HW_DISKNAMES
304.\".It Fa HW_DISKSTATS
305.It Li HW_FLOATINGPT
306Nonzero if the floating point support is in hardware.
307.It Li HW_MACHINE_ARCH
308The machine dependent architecture type.
309.It Li HW_REALMEM
310The bytes of real memory.
311.El
312.Ss CTL_KERN
313The string and integer information available for the CTL_KERN level
314is detailed below.
315The changeable column shows whether a process with appropriate
316privilege may change the value.
317The types of data currently available are process information,
318system vnodes, the open file entries, routing table entries,
319virtual memory statistics, load average history, and clock rate
320information.
321.Bl -column "KERNXMAXFILESPERPROCXXX" "struct clockrateXXX" -offset indent
322.It Sy Second Level Name Ta Sy Type Ta Sy Changeable
323.It Dv KERN_ARGMAX Ta integer Ta no
324.It Dv KERN_BOOTFILE Ta string Ta yes
325.It Dv KERN_BOOTTIME Ta struct timeval Ta no
326.It Dv KERN_CLOCKRATE Ta struct clockinfo Ta no
327.It Dv KERN_FILE Ta struct xfile Ta no
328.It Dv KERN_HOSTID Ta integer Ta yes
329.It Dv KERN_HOSTUUID Ta string Ta yes
330.It Dv KERN_HOSTNAME Ta string Ta yes
331.It Dv KERN_JOB_CONTROL Ta integer Ta no
332.It Dv KERN_MAXFILES Ta integer Ta yes
333.It Dv KERN_MAXFILESPERPROC Ta integer Ta yes
334.It Dv KERN_MAXPROC Ta integer Ta no
335.It Dv KERN_MAXPROCPERUID Ta integer Ta yes
336.It Dv KERN_MAXVNODES Ta integer Ta yes
337.It Dv KERN_NGROUPS Ta integer Ta no
338.It Dv KERN_NISDOMAINNAME Ta string Ta yes
339.It Dv KERN_OSRELDATE Ta integer Ta no
340.It Dv KERN_OSRELEASE Ta string Ta no
341.It Dv KERN_OSREV Ta integer Ta no
342.It Dv KERN_OSTYPE Ta string Ta no
343.It Dv KERN_POSIX1 Ta integer Ta no
344.It Dv KERN_PROC Ta node Ta not applicable
345.It Dv KERN_PROF Ta node Ta not applicable
346.It Dv KERN_QUANTUM Ta integer Ta yes
347.It Dv KERN_SAVED_IDS Ta integer Ta no
348.It Dv KERN_SECURELVL Ta integer Ta raise only
349.It Dv KERN_UPDATEINTERVAL Ta integer Ta no
350.It Dv KERN_VERSION Ta string Ta no
351.It Dv KERN_VNODE Ta struct xvnode Ta no
352.El
353.Bl -tag -width 6n
354.It Li KERN_ARGMAX
355The maximum bytes of argument to
356.Xr execve 2 .
357.It Li KERN_BOOTFILE
358The full pathname of the file from which the kernel was loaded.
359.It Li KERN_BOOTTIME
360A
361.Va struct timeval
362structure is returned.
363This structure contains the time that the system was booted.
364.It Li KERN_CLOCKRATE
365A
366.Va struct clockinfo
367structure is returned.
368This structure contains the clock, statistics clock and profiling clock
369frequencies, the number of micro-seconds per hz tick and the skew rate.
370.It Li KERN_FILE
371Return the entire file table.
372The returned data consists of an array of
373.Va struct xfile ,
374whose size depends on the current number of such objects in the system.
375.It Li KERN_HOSTID
376Get or set the host ID.
377.It Li KERN_HOSTUUID
378Get or set the host's universally unique identifier (UUID).
379.It Li KERN_HOSTNAME
380Get or set the hostname.
381.It Li KERN_JOB_CONTROL
382Return 1 if job control is available on this system, otherwise 0.
383.It Li KERN_MAXFILES
384The maximum number of files that may be open in the system.
385.It Li KERN_MAXFILESPERPROC
386The maximum number of files that may be open for a single process.
387This limit only applies to processes with an effective uid of nonzero
388at the time of the open request.
389Files that have already been opened are not affected if the limit
390or the effective uid is changed.
391.It Li KERN_MAXPROC
392The maximum number of concurrent processes the system will allow.
393.It Li KERN_MAXPROCPERUID
394The maximum number of concurrent processes the system will allow
395for a single effective uid.
396This limit only applies to processes with an effective uid of nonzero
397at the time of a fork request.
398Processes that have already been started are not affected if the limit
399is changed.
400.It Li KERN_MAXVNODES
401The maximum number of vnodes available on the system.
402.It Li KERN_NGROUPS
403The maximum number of supplemental groups.
404.It Li KERN_NISDOMAINNAME
405The name of the current YP/NIS domain.
406.It Li KERN_OSRELDATE
407The kernel release version in the format
408.Ar M Ns Ar mm Ns Ar R Ns Ar xx ,
409where
410.Ar M
411is the major version,
412.Ar mm
413is the two digit minor version,
414.Ar R
415is 0 if release branch, otherwise 1,
416and
417.Ar xx
418is updated when the available APIs change.
419.Pp
420The userland release version is available from
421.In osreldate.h ;
422parse this file if you need to get the release version of
423the currently installed userland.
424.It Li KERN_OSRELEASE
425The system release string.
426.It Li KERN_OSREV
427The system revision string.
428.It Li KERN_OSTYPE
429The system type string.
430.It Li KERN_POSIX1
431The version of
432.St -p1003.1
433with which the system
434attempts to comply.
435.It Li KERN_PROC
436Return selected information about specific running processes.
437.Pp
438For the following names, an array of
439.Va struct kinfo_proc
440structures is returned,
441whose size depends on the current number of such objects in the system.
442.Bl -column "Third Level NameXXXXXX" "Fourth LevelXXXXXX" -offset indent
443.It Sy Third Level Name Ta Sy Fourth Level
444.It Dv KERN_PROC_ALL Ta None
445.It Dv KERN_PROC_PID Ta A process ID
446.It Dv KERN_PROC_PGRP Ta A process group
447.It Dv KERN_PROC_TTY Ta A tty device
448.It Dv KERN_PROC_UID Ta A user ID
449.It Dv KERN_PROC_RUID Ta A real user ID
450.El
451.Pp
452If the third level name is
453.Dv KERN_PROC_ARGS
454then the command line argument
455array is returned in a flattened form, i.e., zero-terminated arguments
456follow each other.
457The total size of array is returned.
458It is also possible for a process to set its own process title this way.
459If the third level name is
460.Dv KERN_PROC_PATHNAME ,
461the path of the
462process' text file is stored.
463For
464.Dv KERN_PROC_PATHNAME ,
465a process ID of
466.Li \-1
467implies the current process.
468.Bl -column "Third Level NameXXXXXX" "Fourth LevelXXXXXX" -offset indent
469.It Sy Third Level Name Ta Sy Fourth Level
470.It Dv KERN_PROC_ARGS Ta "A process ID"
471.It Dv KERN_PROC_PATHNAME Ta "A process ID"
472.El
473.It Li KERN_PROF
474Return profiling information about the kernel.
475If the kernel is not compiled for profiling,
476attempts to retrieve any of the KERN_PROF values will
477fail with
478.Er ENOENT .
479The third level names for the string and integer profiling information
480is detailed below.
481The changeable column shows whether a process with appropriate
482privilege may change the value.
483.Bl -column "GPROFXGMONPARAMXXX" "struct gmonparamXXX" -offset indent
484.It Sy Third Level Name Ta Sy Type Ta Sy Changeable
485.It Dv GPROF_STATE Ta integer Ta yes
486.It Dv GPROF_COUNT Ta u_short[\|] Ta yes
487.It Dv GPROF_FROMS Ta u_short[\|] Ta yes
488.It Dv GPROF_TOS Ta struct tostruct Ta yes
489.It Dv GPROF_GMONPARAM Ta struct gmonparam Ta no
490.El
491.Pp
492The variables are as follows:
493.Bl -tag -width 6n
494.It Li GPROF_STATE
495Returns GMON_PROF_ON or GMON_PROF_OFF to show that profiling
496is running or stopped.
497.It Li GPROF_COUNT
498Array of statistical program counter counts.
499.It Li GPROF_FROMS
500Array indexed by program counter of call-from points.
501.It Li GPROF_TOS
502Array of
503.Va struct tostruct
504describing destination of calls and their counts.
505.It Li GPROF_GMONPARAM
506Structure giving the sizes of the above arrays.
507.El
508.It Li KERN_QUANTUM
509The maximum period of time, in microseconds, for which a process is allowed
510to run without being preempted if other processes are in the run queue.
511.It Li KERN_SAVED_IDS
512Returns 1 if saved set-group and saved set-user ID is available.
513.It Li KERN_SECURELVL
514The system security level.
515This level may be raised by processes with appropriate privilege.
516It may not be lowered.
517.It Li KERN_VERSION
518The system version string.
519.It Li KERN_VNODE
520Return the entire vnode table.
521Note, the vnode table is not necessarily a consistent snapshot of
522the system.
523The returned data consists of an array whose size depends on the
524current number of such objects in the system.
525Each element of the array consists of a
526.Va struct xvnode .
527.El
528.Ss CTL_NET
529The string and integer information available for the CTL_NET level
530is detailed below.
531The changeable column shows whether a process with appropriate
532privilege may change the value.
533.Bl -column "Second Level NameXXXXXX" "routing messagesXXX" -offset indent
534.It Sy Second Level Name Ta Sy Type Ta Sy Changeable
535.It Dv PF_ROUTE Ta routing messages Ta no
536.It Dv PF_INET Ta IPv4 values Ta yes
537.It Dv PF_INET6 Ta IPv6 values Ta yes
538.El
539.Bl -tag -width 6n
540.It Li PF_ROUTE
541Return the entire routing table or a subset of it.
542The data is returned as a sequence of routing messages (see
543.Xr route 4
544for the header file, format and meaning).
545The length of each message is contained in the message header.
546.Pp
547The third level name is a protocol number, which is currently always 0.
548The fourth level name is an address family, which may be set to 0 to
549select all address families.
550The fifth, sixth, and seventh level names are as follows:
551.Bl -column -offset indent "Fifth Level" "Sixth Level" "Seventh Level"
552.It Sy Fifth level Ta Sy Sixth Level Ta Sy Seventh Level
553.It Dv NET_RT_FLAGS Ta rtflags Ta None
554.It Dv NET_RT_DUMP Ta None Ta None or fib number
555.It Dv NET_RT_IFLIST Ta 0 or if_index Ta None
556.It Dv NET_RT_IFMALIST Ta 0 or if_index Ta None
557.It Dv NET_RT_IFLISTL Ta 0 or if_index Ta None
558.El
559.Pp
560The
561.Dv NET_RT_IFMALIST
562name returns information about multicast group memberships on all interfaces
563if 0 is specified, or for the interface specified by
564.Va if_index .
565.Pp
566The
567.Dv NET_RT_IFLISTL
568is like
569.Dv NET_RT_IFLIST ,
570just returning message header structs with additional fields allowing the
571interface to be extended without breaking binary compatibility.
572The
573.Dv NET_RT_IFLISTL
574uses 'l' versions of the message header structures:
575.Va struct if_msghdrl
576and
577.Va struct ifa_msghdrl .
578.It Li PF_INET
579Get or set various global information about the IPv4
580(Internet Protocol version 4).
581The third level name is the protocol.
582The fourth level name is the variable name.
583The currently defined protocols and names are:
584.Bl -column ProtocolXX VariableXX TypeXX ChangeableXX
585.It Sy Protocol Ta Sy Variable Ta Sy Type Ta Sy Changeable
586.It icmp Ta bmcastecho Ta integer Ta yes
587.It icmp Ta maskrepl Ta integer Ta yes
588.It ip Ta forwarding Ta integer Ta yes
589.It ip Ta redirect Ta integer Ta yes
590.It ip Ta ttl Ta integer Ta yes
591.It udp Ta checksum Ta integer Ta yes
592.El
593.Pp
594The variables are as follows:
595.Bl -tag -width 6n
596.It Li icmp.bmcastecho
597Returns 1 if an ICMP echo request to a broadcast or multicast address is
598to be answered.
599.It Li icmp.maskrepl
600Returns 1 if ICMP network mask requests are to be answered.
601.It Li ip.forwarding
602Returns 1 when IP forwarding is enabled for the host,
603meaning that the host is acting as a router.
604.It Li ip.redirect
605Returns 1 when ICMP redirects may be sent by the host.
606This option is ignored unless the host is routing IP packets,
607and should normally be enabled on all systems.
608.It Li ip.ttl
609The maximum time-to-live (hop count) value for an IP packet sourced by
610the system.
611This value applies to normal transport protocols, not to ICMP.
612.It Li udp.checksum
613Returns 1 when UDP checksums are being computed and checked.
614Disabling UDP checksums is strongly discouraged.
615.Pp
616For variables net.inet.*.ipsec, please refer to
617.Xr ipsec 4 .
618.El
619.It Li PF_INET6
620Get or set various global information about the IPv6
621(Internet Protocol version 6).
622The third level name is the protocol.
623The fourth level name is the variable name.
624.Pp
625For variables net.inet6.* please refer to
626.Xr inet6 4 .
627For variables net.inet6.*.ipsec6, please refer to
628.Xr ipsec 4 .
629.El
630.Ss CTL_USER
631The string and integer information available for the CTL_USER level
632is detailed below.
633The changeable column shows whether a process with appropriate
634privilege may change the value.
635.Bl -column "USER_COLL_WEIGHTS_MAXXXX" "integerXXX" -offset indent
636.It Sy Second Level Name Ta Sy Type Ta Sy Changeable
637.It Dv USER_BC_BASE_MAX Ta integer Ta no
638.It Dv USER_BC_DIM_MAX Ta integer Ta no
639.It Dv USER_BC_SCALE_MAX Ta integer Ta no
640.It Dv USER_BC_STRING_MAX Ta integer Ta no
641.It Dv USER_COLL_WEIGHTS_MAX Ta integer Ta no
642.It Dv USER_CS_PATH Ta string Ta no
643.It Dv USER_EXPR_NEST_MAX Ta integer Ta no
644.It Dv USER_LINE_MAX Ta integer Ta no
645.It Dv USER_POSIX2_CHAR_TERM Ta integer Ta no
646.It Dv USER_POSIX2_C_BIND Ta integer Ta no
647.It Dv USER_POSIX2_C_DEV Ta integer Ta no
648.It Dv USER_POSIX2_FORT_DEV Ta integer Ta no
649.It Dv USER_POSIX2_FORT_RUN Ta integer Ta no
650.It Dv USER_POSIX2_LOCALEDEF Ta integer Ta no
651.It Dv USER_POSIX2_SW_DEV Ta integer Ta no
652.It Dv USER_POSIX2_UPE Ta integer Ta no
653.It Dv USER_POSIX2_VERSION Ta integer Ta no
654.It Dv USER_RE_DUP_MAX Ta integer Ta no
655.It Dv USER_STREAM_MAX Ta integer Ta no
656.It Dv USER_TZNAME_MAX Ta integer Ta no
657.El
658.Bl -tag -width 6n
659.It Li USER_BC_BASE_MAX
660The maximum ibase/obase values in the
661.Xr bc 1
662utility.
663.It Li USER_BC_DIM_MAX
664The maximum array size in the
665.Xr bc 1
666utility.
667.It Li USER_BC_SCALE_MAX
668The maximum scale value in the
669.Xr bc 1
670utility.
671.It Li USER_BC_STRING_MAX
672The maximum string length in the
673.Xr bc 1
674utility.
675.It Li USER_COLL_WEIGHTS_MAX
676The maximum number of weights that can be assigned to any entry of
677the LC_COLLATE order keyword in the locale definition file.
678.It Li USER_CS_PATH
679Return a value for the
680.Ev PATH
681environment variable that finds all the standard utilities.
682.It Li USER_EXPR_NEST_MAX
683The maximum number of expressions that can be nested within
684parenthesis by the
685.Xr expr 1
686utility.
687.It Li USER_LINE_MAX
688The maximum length in bytes of a text-processing utility's input
689line.
690.It Li USER_POSIX2_CHAR_TERM
691Return 1 if the system supports at least one terminal type capable of
692all operations described in
693.St -p1003.2 ,
694otherwise 0.
695.It Li USER_POSIX2_C_BIND
696Return 1 if the system's C-language development facilities support the
697C-Language Bindings Option, otherwise 0.
698.It Li USER_POSIX2_C_DEV
699Return 1 if the system supports the C-Language Development Utilities Option,
700otherwise 0.
701.It Li USER_POSIX2_FORT_DEV
702Return 1 if the system supports the FORTRAN Development Utilities Option,
703otherwise 0.
704.It Li USER_POSIX2_FORT_RUN
705Return 1 if the system supports the FORTRAN Runtime Utilities Option,
706otherwise 0.
707.It Li USER_POSIX2_LOCALEDEF
708Return 1 if the system supports the creation of locales, otherwise 0.
709.It Li USER_POSIX2_SW_DEV
710Return 1 if the system supports the Software Development Utilities Option,
711otherwise 0.
712.It Li USER_POSIX2_UPE
713Return 1 if the system supports the User Portability Utilities Option,
714otherwise 0.
715.It Li USER_POSIX2_VERSION
716The version of
717.St -p1003.2
718with which the system attempts to comply.
719.It Li USER_RE_DUP_MAX
720The maximum number of repeated occurrences of a regular expression
721permitted when using interval notation.
722.It Li USER_STREAM_MAX
723The minimum maximum number of streams that a process may have open
724at any one time.
725.It Li USER_TZNAME_MAX
726The minimum maximum number of types supported for the name of a
727timezone.
728.El
729.Ss CTL_VM
730The string and integer information available for the CTL_VM level
731is detailed below.
732The changeable column shows whether a process with appropriate
733privilege may change the value.
734.Bl -column "Second Level NameXXXXXX" "struct loadavgXXX" -offset indent
735.It Sy Second Level Name Ta Sy Type Ta Sy Changeable
736.It Dv VM_LOADAVG Ta struct loadavg Ta no
737.It Dv VM_TOTAL Ta struct vmtotal Ta no
738.It Dv VM_SWAPPING_ENABLED Ta integer Ta maybe
739.It Dv VM_V_FREE_MIN Ta integer Ta yes
740.It Dv VM_V_FREE_RESERVED Ta integer Ta yes
741.It Dv VM_V_FREE_TARGET Ta integer Ta yes
742.It Dv VM_V_INACTIVE_TARGET Ta integer Ta yes
743.It Dv VM_V_PAGEOUT_FREE_MIN Ta integer Ta yes
744.El
745.Bl -tag -width 6n
746.It Li VM_LOADAVG
747Return the load average history.
748The returned data consists of a
749.Va struct loadavg .
750.It Li VM_TOTAL
751Return the system wide virtual memory statistics.
752The returned data consists of a
753.Va struct vmtotal .
754.It Li VM_SWAPPING_ENABLED
7551 if process swapping is enabled or 0 if disabled.
756This variable is
757permanently set to 0 if the kernel was built with swapping disabled.
758.It Li VM_V_FREE_MIN
759Minimum amount of memory (cache memory plus free memory)
760required to be available before a process waiting on memory will be
761awakened.
762.It Li VM_V_FREE_RESERVED
763Processes will awaken the pageout daemon and wait for memory if the
764number of free and cached pages drops below this value.
765.It Li VM_V_FREE_TARGET
766The total amount of free memory (including cache memory) that the
767pageout daemon tries to maintain.
768.It Li VM_V_INACTIVE_TARGET
769The desired number of inactive pages that the pageout daemon should
770achieve when it runs.
771Inactive pages can be quickly inserted into
772process address space when needed.
773.It Li VM_V_PAGEOUT_FREE_MIN
774If the amount of free and cache memory falls below this value, the
775pageout daemon will enter "memory conserving mode" to avoid deadlock.
776.El
777.Sh RETURN VALUES
778.Rv -std
779.Sh FILES
780.Bl -tag -width <netinet/icmpXvar.h> -compact
781.It In sys/sysctl.h
782definitions for top level identifiers, second level kernel and hardware
783identifiers, and user level identifiers
784.It In sys/socket.h
785definitions for second level network identifiers
786.It In sys/gmon.h
787definitions for third level profiling identifiers
788.It In vm/vm_param.h
789definitions for second level virtual memory identifiers
790.It In netinet/in.h
791definitions for third level IPv4/IPv6 identifiers and
792fourth level IPv4/v6 identifiers
793.It In netinet/icmp_var.h
794definitions for fourth level ICMP identifiers
795.It In netinet/icmp6.h
796definitions for fourth level ICMPv6 identifiers
797.It In netinet/udp_var.h
798definitions for fourth level UDP identifiers
799.El
800.Sh ERRORS
801The following errors may be reported:
802.Bl -tag -width Er
803.It Bq Er EFAULT
804The buffer
805.Fa name ,
806.Fa oldp ,
807.Fa newp ,
808or length pointer
809.Fa oldlenp
810contains an invalid address.
811.It Bq Er EINVAL
812The
813.Fa name
814array is less than two or greater than CTL_MAXNAME.
815.It Bq Er EINVAL
816A non-null
817.Fa newp
818is given and its specified length in
819.Fa newlen
820is too large or too small.
821.It Bq Er ENOMEM
822The length pointed to by
823.Fa oldlenp
824is too short to hold the requested value.
825.It Bq Er ENOMEM
826The smaller of either the length pointed to by
827.Fa oldlenp
828or the estimated size of the returned data exceeds the
829system limit on locked memory.
830.It Bq Er ENOMEM
831Locking the buffer
832.Fa oldp ,
833or a portion of the buffer if the estimated size of the data
834to be returned is smaller,
835would cause the process to exceed its per-process locked memory limit.
836.It Bq Er ENOTDIR
837The
838.Fa name
839array specifies an intermediate rather than terminal name.
840.It Bq Er EISDIR
841The
842.Fa name
843array specifies a terminal name, but the actual name is not terminal.
844.It Bq Er ENOENT
845The
846.Fa name
847array specifies a value that is unknown.
848.It Bq Er EPERM
849An attempt is made to set a read-only value.
850.It Bq Er EPERM
851A process without appropriate privilege attempts to set a value.
852.El
853.Sh SEE ALSO
854.Xr confstr 3 ,
855.Xr kvm 3 ,
856.Xr sysconf 3 ,
857.Xr sysctl 8
858.Sh HISTORY
859The
860.Fn sysctl
861function first appeared in
862.Bx 4.4 .
863