get or set kernel state

sysctl [-n] -a | -A
sysctl [-b|X n] name
sysctl [-b|X n] -w name=value
sysctl [-b|X n] -X

retrieves kernel state and allows processes 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.
-a List all the currently available non-opaque values.
Ignored if one or more variable names are specified on the command line.
-A List ALL MIB variables including opaque variables (which are normally suppressed). format and length are displayed, as well as a hex dump of the first 16 bytes.
Produces identical output to -a El Captian 4/15/16
Differeces in Mac OS High Sierra.
-X displays hex dump
user.cs_path: /usr/bin:/bin:/usr/sbin:/sbin
user.bc_base_max: 0x00000063
user.bc_dim_max: 0x00000800
user.bc_scale_max: 0x00000063

-b Output in binary, value only (direct output to file)
-n Show only values, not names. Useful for setting shell variables.

For example, to save the pagesize in variable $psize:

set psize=`sysctl -n hw.pagesize`
-w name=value Sets values.
If just a MIB style name is given, the corresponding value is retrieved.

The information available from sysctl consists of integers, strings, and tables.
The tabular information can only be retrieved by special programs such as ps, systat, and netstat.

Name                  Type    Changable
kern.ostype           string        no
kern.osrelease        string        no
kern.osrevision       integer       no
kern.version          string        no
kern.maxvnodes        integer       yes
kern.maxproc          integer       yes
kern.maxfiles         integer       yes
kern.argmax           integer       no
kern.securelevel      integer       raise only
kern.hostname         string        yes
kern.hostid           integer       yes
kern.clockrate        struct        no
kern.posix1version    integer       no
kern.ngroups          integer       no
kern.job_control      integer       no
kern.saved_ids        integer       no
kern.link_max         integer       no
kern.max_canon        integer       no
kern.max_input        integer       no
kern.name_max         integer       no
kern.path_max         integer       no
kern.pipe_buf         integer       no
kern.chown_restricted integer       no
kern.no_trunc         integer       no
kern.vdisable         integer       no
kern.boottime         struct        no
Name                  Type    Changable 
vm.loadavg            struct        no
vm.swapusage          struct        no

machdep.console_device    dev_t     no

net.inet.ip.forwarding integer      yes
net.inet.ip.redirect  integer       yes
net.inet.ip.ttl       integer       yes
net.inet.icmp.maskrepl integer      yes
net.inet.udp.checksum integer       yes

hw.machine            string        no
hw.model              string        no
hw.ncpu               integer       no
hw.byteorder          integer       no
hw.physmem            integer       no
hw.usermem            integer       no
hw.memsize            integer       no
hw.pagesize           integer       no

Name                  Type    Changable
user.cs_path          string        no
user.bc_base_max      integer       no
user.bc_dim_max       integer       no
user.bc_scale_max     integer       no
user.bc_string_max    integer       no
user.coll_weights_max integer       no
user.expr_nest_max    integer       no
user.line_max         integer       no
user.re_dup_max       integer       no

user.posix2_version   integer       no
user.posix2_c_bind    integer       no
user.posix2_c_dev     integer       no
user.posix2_char_term integer       no
user.posix2_fort_dev  integer       no
user.posix2_fort_run  integer       no
user.posix2_localedef integer       no
user.posix2_sw_dev    integer       no
user.posix2_upe       integer       no
sysctl can get or set debugging variables that have been identified for its display.

sysctl debug
El Capitian 4/14/16

debug.lowpri_throttle_max_iosize: 131072
debug.lowpri_throttle_tier1_window_msecs: 25
debug.lowpri_throttle_tier2_window_msecs: 100
debug.lowpri_throttle_tier3_window_msecs: 500
debug.lowpri_throttle_tier1_io_period_msecs: 15
debug.lowpri_throttle_tier2_io_period_msecs: 50
debug.lowpri_throttle_tier3_io_period_msecs: 200
debug.lowpri_throttle_tier1_io_period_ssd_msecs: 5
debug.lowpri_throttle_tier2_io_period_ssd_msecs: 15
debug.lowpri_throttle_tier3_io_period_ssd_msecs: 25
debug.lowpri_throttle_enabled: 1

debug.bpf_bufsize:      4096
debug.bpf_maxbufsize: 524288
debug.bpf_maxdevices:    256
debug.bpf_wantpktap: 0
debug.bpf_debug: 0

debug.sched: 0
debug.toggle_address_reuse: 0
debug.sys_override_enabled: 1
debug.kextlog: 4083
debug.swd_delay_duration: 0

debug.iokit: 0
debug.iotrace: 0
debug.darkwake: 3
debug.noidle: 0
debug.wdtlog: 95013m1/095033m1/095053m1/095073m1/
Information about the filesystems that have been compiled into the running system.
sysctl vfs
By default, only filesystems that are actively being used are listed. -A lists all the filesystems compiled into the running kernel.


All kernal variables: sysctl kern

Maximum number of processes allowed in the system: sysctl kern.maxproc

clock rate : sysctl kern.clockrate

load average history : sysctl vm.loadavg

swap space usage : sysctl vm.swapusage

Set the maximum number of processes allowed in the system to 1000: sysctl -w kern.maxproc=1000

Linux sudo sysctl vm
vm.admin_reserve_kbytes = 8192
vm.block_dump = 0
vm.compact_unevictable_allowed = 1

vm.dirty_background_bytes = 0
vm.dirty_background_ratio = 10 

vm.dirty_bytes = 0
vm.dirty_ratio = 20

vm.dirty_expire_centisecs = 3000
vm.dirty_writeback_centisecs = 500
vm.dirtytime_expire_seconds = 43200
vm.drop_caches = 0
vm.extfrag_threshold = 500
vm.laptop_mode = 0
vm.legacy_va_layout = 0
vm.lowmem_reserve_ratio = 32
vm.max_map_count = 65530
vm.min_free_kbytes = 16384
vm.mmap_min_addr = 4096
vm.mmap_rnd_bits = 8
vm.nr_pdflush_threads = 0
vm.oom_dump_tasks = 1
vm.oom_kill_allocating_task = 0
vm.overcommit_kbytes = 0
vm.overcommit_memory = 0
vm.overcommit_ratio = 50 = 3
vm.panic_on_oom = 0
vm.percpu_pagelist_fraction = 0
vm.swappiness = 10
vm.user_reserve_kbytes = 13770
vm.vfs_cache_pressure = 100
vm.watermark_scale_factor = 10
cat /proc/vmstat | egrep "dirty|writeback"
 nr_dirty 878  pages waiting
 nr_writeback 0
 nr_writeback_temp 0



<sys/sysctl.h> top level identifiers, second level kernel and hardware identifiers, and user level identifiers
<sys/socket.h> second level network identifiers
<sys/gmon.h> third level profiling identifiers
<vm/vm_param.h> second level virtual memory identifiers
<netinet/in.h> third level Internet identifiers and fourth level IP identifiers
<netinet/icmp_var.h> fourth level ICMP identifiers
<netinet/udp_var.h> fourth level UDP identifiers


systemctl, sysctl, systemd

For a detailed description of these variable see sysctl(3).