NAME
sysctl
—
get or set kernel state
SYNOPSIS
sysctl |
[-Aan ] |
sysctl |
[-n ] name ... |
sysctl |
[-nq ]
name=value ... |
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.
When retrieving a variable, a subset of the MIB name may be specified to retrieve a list of variables in that subset. For example, to list all the machdep variables:
$ sysctl machdep
When setting a variable, the MIB name should be followed by an equal sign and the new value.
The options are as follows:
-A
- List all the known MIB names including tables. Those with string or
integer values will be printed as with the
-a
flag; for the table values, the name of the utility to retrieve them is given. -a
- List all the currently available string or integer values. This is the
default, if no parameters are given to
sysctl
. -n
- Suppress printing of the field name, only output the field value. Useful
for setting shell variables. For example, to set the psize shell variable
to the pagesize of the hardware:
# set psize=`sysctl -n hw.pagesize`
-q
- Suppress all output when setting a variable. This option overrides the
behaviour of
-n
. - name=value
- Attempt to set the specified variable name to value.
The information available from sysctl
consists of integers, strings, and tables. For a detailed description of the
variables, see
sysctl(3). Tables can only be retrieved by special purpose programs
such as ps(1), systat(1), and
netstat(1).
sysctl
can extract information about the
filesystems that have been compiled into the running system. This
information can be obtained by using the command:
$ sysctl vfs.mounts
By default, only filesystems that are actively being used are
listed. Use of the -A
flag lists all the filesystems
compiled into the running kernel.
FILES
<sys/sysctl.h>
- definitions for top level identifiers and second level kernel and hardware identifiers
<sys/socket.h>
- definitions for second level network identifiers
<sys/gmon.h>
- definitions for third level profiling identifiers
<uvm/uvm_param.h>
- definitions for second level virtual memory identifiers
<uvm/uvm_swap_encrypt.h>
- definitions for third level virtual memory identifiers
<netinet/in.h>
- definitions for third level IPv4/v6 identifiers and fourth level IPv4/v6 identifiers
<netinet/ip_divert.h>
- definitions for fourth level divert identifiers
<netinet/icmp_var.h>
- definitions for fourth level ICMP identifiers
<netinet6/icmp6.h>
- definitions for fourth level ICMPv6 identifiers
<netinet/tcp_var.h>
- definitions for fourth level TCP identifiers
<netinet/udp_var.h>
- definitions for fourth level UDP identifiers
<ddb/db_var.h>
- definitions for second level ddb identifiers
<sys/mount.h>
- definitions for second level vfs identifiers
<nfs/nfs.h>
- definitions for third level NFS identifiers
<miscfs/fuse/fusefs.h>
- definitions for third level fusefs identifiers
<ufs/ffs/ffs_extern.h>
- definitions for third level FFS identifiers
<machine/cpu.h>
- definitions for second level CPU identifiers
EXAMPLES
To retrieve the maximum number of processes allowed in the system:
$ sysctl kern.maxproc
To set the maximum number of processes allowed in the system to 1000:
# sysctl
kern.maxproc=1000
To retrieve information about the system clock rate:
$ sysctl kern.clockrate
To retrieve information about the load average history:
$ sysctl vm.loadavg
To make the chown(2) system call use traditional BSD semantics (don't clear setuid/setgid bits):
# sysctl
fs.posix.setuid=0
To set the list of reserved TCP ports that should not be allocated by the kernel dynamically:
# sysctl
net.inet.tcp.baddynamic=749,750,751,760,761,871
# sysctl
net.inet.udp.baddynamic=749,750,751,760,761,871,1024-2048
This can be used to keep daemons from stealing a specific port that another program needs to function. List elements may be separated by commas and/or whitespace; a hyphen may be used to specify a range of ports.
It is also possible to add or remove ports from the current list:
# sysctl net.inet.tcp.baddynamic=+748,+6000-6999 # sysctl net.inet.tcp.baddynamic=-871
To set the amount of shared memory available in the system and the maximum number of shared memory segments:
# sysctl kern.shminfo.shmmax=33554432 # sysctl kern.shminfo.shmseg=32
To place core dumps from issetugid(2) programs (in this example bgpd(8)) into a safe place for debugging purposes:
# mkdir -m 700 /var/crash/bgpd # sysctl kern.nosuidcoredump=3
SEE ALSO
HISTORY
sysctl
first appeared in
4.4BSD.