SYSCTL(3)

๐Ÿ“ฆ
version 15.1 ยท 2 versions
, in freebsd 15.1

Bestie, you're looking at SYSCTL(3) from the Library Functions Manual โ€” aka the libc page for getting and setting system info, and it's honestly giving main character energy in the kernel-adjacent department. Let's go.


โœจ NAME โœจ

sysctl, sysctlbyname, sysctlnametomib โ€” get or set system information. That's the whole three-name situation, and yes, they're all in the same friend group.

๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C Library (libc, -lc). Slay.

๐Ÿ› ๏ธ SYNOPSIS ๐Ÿ› ๏ธ

The vibe check, exactly as the header says:

#include <sys/sysctl.h>

int
sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp,
    const void *newp, size_t newlen);

int
sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
    const void *newp, size_t newlen);

int
sysctlnametomib(const char *name, int *mibp, size_t *sizep);

๐Ÿ’… DESCRIPTION ๐Ÿ’…

Okay so sysctl() retrieves system information and lets processes with appropriate privileges set system information. The info it can hand you consists of integers, strings, and tables โ€” like a little buffet of kernel facts ๐Ÿ“. You can also retrieve and set information from the command interface using the sysctl(8) utility. Obsessed.

Unless explicitly noted below, sysctl() returns a consistent snapshot of the data requested. Consistency is obtained by locking the destination buffer into memory so that the data may be copied out without blocking. Calls to sysctl() are serialized to avoid deadlock โ€” yes, they queue politely, no chaos.

The state is described using a โ€œManagement Information Baseโ€ (MIB) style name, listed in name, which is a namelen length array of integers. If that sounds like a coordinate system for kernel data, that's because it lowkey is.

The sysctlbyname() function accepts an ASCII representation of the name and internally looks up the integer name vector. Apart from that, it behaves the same as the standard sysctl() function. Same energy, friendlier spelling โœจ.

The information is copied into the buffer specified by oldp. The size of the buffer is given by the location specified by oldlenp before the call, and that location gives the amount of data copied after a successful call and after a call that returns with the error code ENOMEM. So oldlenp is doing double duty: size in, size out. Not me being impressed by a pointer ๐Ÿ˜ญ.

If the amount of data available is greater than the size of the buffer supplied, the call supplies as much data as fits in the buffer provided and returns with the error code ENOMEM. Translation: it fills what it can, then tells you the buffer was too small. If the old value is not desired, oldp and oldlenp should be set to NULL.

bestie warning: too-small buffer = partial data plus ENOMEM, not a full clean read. Handle it, don't ignore it ๐Ÿ’….

The size of the available data can be determined by calling sysctl() with the NULL argument for oldp. The size of the available data will be returned in the location pointed to by oldlenp. For some operations, the amount of space may change often. For these operations, the system attempts to round up so that the returned size is large enough for a call to return the data shortly thereafter. It's giving โ€œI got you, but also data is feral.โ€

To set a new value, newp is set to point to a buffer of length newlen from which the requested value is to be taken. If a new value is not to be set, newp should be set to NULL and newlen set to 0. Clean ๐ŸŽ€.

The sysctlnametomib() function accepts an ASCII representation of the name, looks up the integer name vector, and returns the numeric representation in the mib array pointed to by mibp. The number of elements in the mib array is given by the location specified by sizep before the call, and that location gives the number of entries copied after a successful call. The resulting mib and size may be used in subsequent sysctl() calls to get the data associated with the requested ASCII name.

This interface is intended for use by applications that want to repeatedly request the same variable โ€” and here's the flex โ€” the sysctl() function runs in about a third the time as the same request made via the sysctlbyname() function. The sysctlnametomib() function is also useful for fetching mib prefixes and then adding a final component. For example, to fetch process information for processes with pid's less than 100:

int i, mib[4];
size_t len;
struct kinfo_proc kp;

/* Fill out the first three components of the mib */
len = 4;
sysctlnametomib("kern.proc.pid", mib, &len);

/* Fetch and print entries for pid's < 100 */
for (i = 0; i < 100; i++) {
        mib[3] = i;
        len = sizeof(kp);
        if (sysctl(mib, 4, &kp, &len, NULL, 0) == -1)
                perror("sysctl");
        else if (len > 0)
                printkproc(&kp);
}

The top level names are defined with a CTL_ prefix in <sys/sysctl.h>, and are as follows. The next and subsequent levels down are found in the include files listed here, and described in separate sections below. So here's the whole top-level lineup, no cap:

  • CTL_DEBUG โ€” next level names: <sys/sysctl.h>; description: Debugging.
  • CTL_VFS โ€” next level names: <sys/mount.h>; description: File system.
  • CTL_HW โ€” next level names: <sys/sysctl.h>; description: Generic CPU, I/O.
  • CTL_KERN โ€” next level names: <sys/sysctl.h>; description: High kernel limits.
  • CTL_MACHDEP โ€” next level names: <sys/sysctl.h>; description: Machine dependent.
  • CTL_NET โ€” next level names: <sys/socket.h>; description: Networking.
  • CTL_USER โ€” next level names: <sys/sysctl.h>; description: User-level.
  • CTL_VM โ€” next level names: <vm/vm_param.h>; description: Virtual memory.

For example, the following retrieves the maximum number of processes allowed in the system:

int mib[2], maxproc;
size_t len;

mib[0] = CTL_KERN;
mib[1] = KERN_MAXPROC;
len = sizeof(maxproc);
sysctl(mib, 2, &maxproc, &len, NULL, 0);

To retrieve the standard search path for the system utilities:

int mib[2];
size_t len;
char *p;

mib[0] = CTL_USER;
mib[1] = USER_CS_PATH;
sysctl(mib, 2, NULL, &len, NULL, 0);
p = malloc(len);
sysctl(mib, 2, p, &len, NULL, 0);

๐Ÿž CTL_DEBUG ๐Ÿž

The debugging variables vary from system to system. A debugging variable may be added or deleted without need to recompile sysctl() to know about it. Each time it runs, sysctl() gets the list of debugging variables from the kernel and displays their current values. The system defines twenty (struct ctldebug) variables named debug0 through debug19. They are declared as separate variables so that they can be individually initialized at the location of their associated variable. The loader prevents multiple use of the same variable by issuing errors if a variable is initialized in more than one place. For example, to export the variable dospecialcheck as a debugging variable, the following declaration would be used:

int dospecialcheck = 1;
struct ctldebug debug5 = { "dospecialcheck", &dospecialcheck };

๐Ÿ—‚๏ธ CTL_VFS ๐Ÿ—‚๏ธ

A distinguished second level name, VFS_GENERIC, is used to get general information about all file systems. One of its third level identifiers is VFS_MAXTYPENUM that gives the highest valid file system type number. Its other third level identifier is VFS_CONF that returns configuration information about the file system type given as a fourth level identifier (see getvfsbyname(3) as an example of its use). The remaining second level identifiers are the file system type number returned by a statfs(2) call or from VFS_CONF. The third level identifiers available for each file system are given in the header file that defines the mount argument structure for that file system. Very โ€œbring your own header fileโ€ of it ๐Ÿฆ‹.

๐Ÿ–ฅ๏ธ CTL_HW ๐Ÿ–ฅ๏ธ

The string and integer information available for the CTL_HW level is detailed below. The changeable column shows whether a process with appropriate privilege may change the value. (Spoiler: in this list, none of them are changeable โ€” they're all โ€œnoโ€ bestie.)

  • HW_MACHINE โ€” type: string; changeable: no.
  • HW_MODEL โ€” type: string; changeable: no.
  • HW_NCPU โ€” type: integer; changeable: no.
  • HW_BYTEORDER โ€” type: integer; changeable: no.
  • HW_PHYSMEM โ€” type: integer; changeable: no.
  • HW_USERMEM โ€” type: integer; changeable: no.
  • HW_PAGESIZE โ€” type: integer; changeable: no.
  • HW_FLOATINGPT โ€” type: integer; changeable: no.
  • HW_MACHINE_ARCH โ€” type: string; changeable: no.
  • HW_REALMEM โ€” type: integer; changeable: no.
  • HW_AVAILPAGES โ€” type: integer; changeable: no.

And here's what each one actually means, because the names alone are lowkey cryptic:

  • HW_MACHINE โ€” The machine class.
  • HW_MODEL โ€” The machine model.
  • HW_NCPU โ€” The number of cpus.
  • HW_BYTEORDER โ€” The byteorder (4321 or 1234).
  • HW_PHYSMEM โ€” Amount of physical memory (in bytes), minus the amount used by the kernel, pre-loaded modules, and (on x86) the dcons buffer.
  • HW_USERMEM โ€” Amount of memory (in bytes) which is not wired.
  • HW_PAGESIZE โ€” The software page size.
  • HW_FLOATINGPT โ€” Nonzero if the floating point support is in hardware.
  • HW_MACHINE_ARCH โ€” The machine dependent architecture type.
  • HW_REALMEM โ€” Amount of memory (in bytes) reported by the firmware. That value is sometimes not sane; in that case, the kernel reports the max memory address instead.
  • HW_AVAILPAGES โ€” The same value as HW_PHYSMEM, measured in pages rather than bytes.

๐Ÿง  CTL_KERN ๐Ÿง 

The string and integer information available for the CTL_KERN level is detailed below. The changeable column shows whether a process with appropriate privilege may change the value. The types of data currently available are process information, system vnodes, the open file entries, routing table entries, virtual memory statistics, load average history, and clock rate information.

okay so hereโ€™s the second-level name roster, bestie โ€” every single one, with its type and whether you can change it, no skips, periodt:

  • KERN_ARGMAX โ€” type: integer ยท changeable: no
  • KERN_ARND โ€” type: integer ยท changeable: no
  • KERN_BOOTFILE โ€” type: string ยท changeable: yes
  • KERN_BOOTTIME โ€” type: struct timeval ยท changeable: no
  • KERN_CLOCKRATE โ€” type: struct clockinfo ยท changeable: no
  • KERN_FILE โ€” type: struct xfile ยท changeable: no
  • KERN_HOSTID โ€” type: integer ยท changeable: yes
  • KERN_HOSTUUID โ€” type: string ยท changeable: yes
  • KERN_HOSTNAME โ€” type: string ยท changeable: yes
  • KERN_IOV_MAX โ€” type: integer ยท changeable: yes
  • KERN_JOB_CONTROL โ€” type: integer ยท changeable: no
  • KERN_LOCKF โ€” type: struct kinfo_lockf ยท changeable: no
  • KERN_LOGSIGEXIT โ€” type: integer ยท changeable: yes
  • KERN_MAXFILES โ€” type: integer ยท changeable: yes
  • KERN_MAXFILESPERPROC โ€” type: integer ยท changeable: yes
  • KERN_MAXPHYS โ€” type: integer ยท changeable: no
  • KERN_MAXPROC โ€” type: integer ยท changeable: no
  • KERN_MAXPROCPERUID โ€” type: integer ยท changeable: yes
  • KERN_MAXVNODES โ€” type: integer ยท changeable: yes
  • KERN_NGROUPS โ€” type: integer ยท changeable: no
  • KERN_NISDOMAINNAME โ€” type: string ยท changeable: yes
  • KERN_OSRELDATE โ€” type: integer ยท changeable: no
  • KERN_OSRELEASE โ€” type: string ยท changeable: no
  • KERN_OSREV โ€” type: integer ยท changeable: no
  • KERN_OSTYPE โ€” type: string ยท changeable: no
  • KERN_POSIX1 โ€” type: integer ยท changeable: no
  • KERN_PROC โ€” type: node ยท changeable: not applicable
  • KERN_PS_STRINGS โ€” type: integer ยท changeable: no
  • KERN_SAVED_IDS โ€” type: integer ยท changeable: no
  • KERN_SECURELVL โ€” type: integer ยท changeable: raise only
  • KERN_UPDATEINTERVAL โ€” type: integer ยท changeable: no
  • KERN_USRSTACK โ€” type: integer ยท changeable: no
  • KERN_VERSION โ€” type: string ยท changeable: no

KERN_ARGMAX โ€” the maximum bytes of argument to execve(2).

KERN_ARND โ€” arc4rand(9) fills the buffer with random bytes from the in-kernel random data generator. This is an alternative interface for read(2) of the random(4) device, which does not depend on accessibility and correct mounting options of the devfs(4) node.

KERN_BOOTFILE โ€” the full pathname of the file from which the kernel was loaded.

KERN_BOOTTIME โ€” a struct timeval structure is returned. This structure contains the time that the system was booted.

KERN_CLOCKRATE โ€” a struct clockinfo structure is returned. This structure contains the clock, statistics clock and profiling clock frequencies, the number of micro-seconds per hz tick and the skew rate.

KERN_FILE โ€” return the entire file table. The returned data consists of an array of struct xfile, whose size depends on the current number of such objects in the system.

KERN_HOSTID โ€” get or set the host ID.

KERN_HOSTUUID โ€” get or set the hostโ€™s universally unique identifier (UUID).

KERN_HOSTNAME โ€” get or set the hostname.

KERN_IOV_MAX โ€” the maximum accepted number of elements in an input-output vector (iovec), see readv(2) and writev(2).

KERN_JOB_CONTROL โ€” return 1 if job control is available on this system, otherwise 0.

KERN_LOCKF โ€” returns the list of the file advisory locks currently known to kernel.

KERN_LOGSIGEXIT โ€” controls logging of process exit due to untrapped signals.

KERN_MAXFILES โ€” the maximum number of files that may be open in the system.

KERN_MAXFILESPERPROC โ€” the maximum number of files that may be open for a single process. This limit only applies to processes with an effective uid of nonzero at the time of the open request. Files that have already been opened are not affected if the limit or the effective uid is changed.

KERN_MAXPHYS โ€” specifies the maximum block I/O size. Can be changed by the tunable kern.maxphys.

KERN_MAXPROC โ€” the maximum number of concurrent processes the system will allow.

KERN_MAXPROCPERUID โ€” the maximum number of concurrent processes the system will allow for a single effective uid. This limit only applies to processes with an effective uid of nonzero at the time of a fork request. Processes that have already been started are not affected if the limit is changed.

KERN_MAXVNODES โ€” the maximum number of vnodes available on the system.

KERN_NGROUPS โ€” the maximum number of supplemental groups.

KERN_NISDOMAINNAME โ€” the name of the current YP/NIS domain.

KERN_OSRELDATE โ€” the kernel release version in the format MmmRxx, where M is the major version, mm is the two digit minor version, R is 0 if release branch, otherwise 1, and xx is updated when the available APIs change.

The userland release version is available from <osreldate.h>; parse this file if you need to get the release version of the currently installed userland.

KERN_OSRELEASE โ€” the system release string.

KERN_OSREV โ€” the system revision string.

KERN_OSTYPE โ€” the system type string.

KERN_POSIX1 โ€” the version of IEEE Std 1003.1 (โ€œPOSIX.1โ€) with which the system attempts to comply.

KERN_PROC โ€” return selected information about specific running processes.

For the following names, an array of struct kinfo_proc structures is returned, whose size depends on the current number of such objects in the system:

  • KERN_PROC_ALL โ€” fourth level: None
  • KERN_PROC_PID โ€” fourth level: A process ID
  • KERN_PROC_PGRP โ€” fourth level: A process group
  • KERN_PROC_SESSION โ€” fourth level: A session
  • KERN_PROC_TTY โ€” fourth level: A tty device
  • KERN_PROC_UID โ€” fourth level: effective user ID
  • KERN_PROC_RUID โ€” fourth level: A real user ID
  • KERN_PROC_GID โ€” fourth level: effective group ID
  • KERN_PROC_RGID โ€” fourth level: A real group ID

For the following names, the miscellaneous information about the target process, which is specified by the fourth level of the oid name, is returned. A process ID of -1 specifies the current process.

  • KERN_PROC_ARGS โ€” fourth level: Set of strings
  • KERN_PROC_PATHNAME โ€” fourth level: String
  • KERN_PROC_KSTACK โ€” fourth level: struct kinfo_stack []
  • KERN_PROC_VMMAP โ€” fourth level: struct kinfo_vmentry []
  • KERN_PROC_FILEDESC โ€” fourth level: struct kinfo_file []
  • KERN_PROC_GROUPS โ€” fourth level: gid_t []
  • KERN_PROC_ENV โ€” fourth level: Set of strings
  • KERN_PROC_AUXV โ€” fourth level: Elf_Auxinfo []
  • KERN_PROC_RLIMIT โ€” fourth level: Integer
  • KERN_PROC_PS_STRINGS โ€” fourth level: Integer
  • KERN_PROC_UMASK โ€” fourth level: Integer/short
  • KERN_PROC_OSREL โ€” fourth level: Integer
  • KERN_PROC_SIGTRAMP โ€” fourth level: Integer
  • KERN_PROC_CWD โ€” fourth level: String
  • KERN_PROC_NFDS โ€” fourth level: Integer
  • KERN_PROC_SIGFASTBLK โ€” fourth level: Integer
  • KERN_PROC_VM_LAYOUT โ€” fourth level: struct kinfo_vm_layout
  • KERN_PROC_RLIMIT_USAGE โ€” fourth level: rlim_t []
  • KERN_PROC_KQUEUE โ€” fourth level: struct kinfo_knote []

KERN_PROC_ARGS โ€” the command line argument array is returned in a flattened form, i.e., zero-terminated arguments follow each other. The total size of array is returned. It is also possible for a process to set its own process title this way.

KERN_PROC_PATHNAME โ€” the path of the processโ€™ text file is returned.

KERN_PROC_KSTACK โ€” the in-kernel call stacks for the threads of the specified process.

KERN_PROC_VMMAP โ€” the description of the map entries for the process. Also refer to kinfo_getvmmap(3).

KERN_PROC_FILEDESC โ€” the file descriptors for files opened in the specified process. Also refer to kinfo_getfile(3).

KERN_PROC_GROUPS โ€” groups associated with the process.

KERN_PROC_ENV โ€” the set of strings representing the environment of the specified process. ๐Ÿซถ

okay so real talk from the kernel's POV: environment only exists at the moment of the execve(2) system call. this node method tries to reconstruct the env from the breadcrumbs left behind in the process address space, but ngl it is not guaranteed to succeed, and it is not guaranteed to show you the current value the program is actually keeping. ๐Ÿ’€

  • KERN_PROC_AUXV โ€” the set of ELF auxv entries โœจ. see the note above about environment, because it applies here too โ€” same vibes, same caveats.
  • KERN_PROC_RLIMIT โ€” you must supply an additional OID name element specifying the resource name as in getrlimit(2). the call returns the given resource limit for the process ๐Ÿซถ.
  • KERN_PROC_PS_STRINGS โ€” returns the location of the ps_strings structure at the time of the last call to execve(2) in the specified process ๐Ÿ‘‘
  • KERN_PROC_UMASK โ€” the current umask value, see umask(2) ๐ŸŽ€
  • KERN_PROC_OSREL โ€” the value of osrel for the process, i.e. the osrel the currently executed image was compiled for. it's read from the note of the elf executable at execve(2) time. it might be modified by the process (they can be messy like that) ๐Ÿ™ˆ
  • KERN_PROC_SIGTRAMP โ€” address of the signal trampoline in the process address space, where โ€” simplifying a lot โ€” the kernel passes control for signal delivery ๐ŸŒธ
  • KERN_PROC_CWD โ€” returns the current working directory for the process ๐Ÿฆ‹
  • KERN_PROC_NFDS โ€” returns the total number of opened file descriptors for the process ๐Ÿ”ฅ
  • KERN_PROC_SIGFASTBLK โ€” returns the address of the sigfastblock(2) location, if active โœจ
  • KERN_PROC_VM_LAYOUT โ€” fills a structure describing the process virtual address space layout ๐Ÿงš
  • KERN_PROC_RLIMIT_USAGE โ€” like KERN_PROC_RLIMIT, but instead of the limit it returns the accounted resource usage ๐Ÿ’…. for resources that don't have a meaningful current value, -1 is returned.
  • KERN_PROC_KQUEUE โ€” fills an array of structures describing events registered with the specified kqueue ๐Ÿ‘‘. the next two node's values are the pid and kqfd โ€” the process ID of the process, and the file descriptor of the kqueue in that process, to query.

KERN_PS_STRINGS ๐ŸŽ€

Reports the location of the process ps_strings structure after exec, for the ABI of the querying process ๐Ÿ’–

KERN_SAVED_IDS ๐ŸŒˆ

Returns 1 if saved set-group and saved set-user ID is available, otherwise... well, that's the whole test โœจ

KERN_SECURELVL ๐Ÿ”’

The system security level. this level may be raised by processes with appropriate privilege, but it may not be lowered ๐Ÿ˜ค periodt. no take-backs.

KERN_USRSTACK ๐Ÿซถ

Reports the top of the main thread user stack for the current process.

KERN_VERSION โญ

The system version string. iconic. show-off behavior.


๐ŸŒ CTL_NET

the string and integer info available at the CTL_NET level is detailed below bestie. the changeable column tells you whether a process with appropriate privilege can change the value:

  • PF_ROUTE โ€” routing messages โ€” not changeable ๐Ÿšซ
  • PF_INET โ€” IPv4 values โ€” changeable โœ…
  • PF_INET6 โ€” IPv6 values โ€” changeable โœ…

๐Ÿ›ฃ๏ธ PF_ROUTE

Return the entire routing table, or just a subset of it. the data comes back as a sequence of routing messages (see route(4) for the header file, format and meaning) ๐Ÿ’œ. the length of each message is contained in the message header, iykyk.

The third level name is a protocol number, which is currently always 0. the fourth level name is an address family, and you can set it to 0 to select all address families ๐ŸŒˆ. the fifth, sixth and seventh level names go like this:

  • NET_RT_FLAGS โ€” sixth level: rtflags โ€” seventh level: None
  • NET_RT_DUMP โ€” sixth level: None โ€” seventh level: None or fib number
  • NET_RT_IFLIST โ€” sixth level: 0 or if_index โ€” seventh level: None
  • NET_RT_IFMALIST โ€” sixth level: 0 or if_index โ€” seventh level: None
  • NET_RT_IFLISTL โ€” sixth level: 0 or if_index โ€” seventh level: None
  • NET_RT_NHOPS โ€” sixth level: None โ€” seventh level: fib number

The NET_RT_IFMALIST name returns info about multicast group memberships on all interfaces if 0 is specified, or for the interface specified by if_index ๐Ÿฆ‹

The NET_RT_IFLISTL is like NET_RT_IFLIST, just returning message header structs with additional fields allowing the interface to be extended without breaking binary compatibility โœจ. NET_RT_IFLISTL uses the 'l' versions of the message header structures: struct if_msghdrl and struct ifa_msghdrl.

NET_RT_NHOPS returns all nexthops for the specified address family in the given fib ๐Ÿ‘‘

๐Ÿ“ก PF_INET

Get or set various global info about IPv4 (Internet Protocol version 4) ๐Ÿ’–. the third level name is the protocol, the fourth level name is the variable name. here's the currently defined values, no cap:

  • icmp.bmcastecho โ€” type: integer โ€” changeable: yes
  • icmp.maskrepl โ€” type: integer โ€” changeable: yes
  • ip.forwarding โ€” type: integer โ€” changeable: yes
  • ip.redirect โ€” type: integer โ€” changeable: yes
  • ip.ttl โ€” type: integer โ€” changeable: yes
  • udp.checksum โ€” type: integer โ€” changeable: yes

and here's what each one actually means ๐Ÿ’…:

  • icmp.bmcastecho โ€” returns 1 if an ICMP echo request to a broadcast or multicast address is to be answered ๐Ÿ™ˆ
  • icmp.maskrepl โ€” returns 1 if ICMP network mask requests are to be answered ๐ŸŽ€
  • ip.forwarding โ€” returns 1 when IP forwarding is enabled for the host, meaning the host is acting as a router ๐Ÿ‘‘
  • ip.redirect โ€” returns 1 when ICMP redirects may be sent by the host. this option is ignored unless the host is routing IP packets, and it should normally be enabled on all systems โญ
  • ip.ttl โ€” the maximum time-to-live (hop count) value for an IP packet sourced by the system ๐ŸŒธ. this value applies to normal transport protocols, not to ICMP.
  • udp.checksum โ€” returns 1 when UDP checksums are being computed and checked. disabling UDP checksums is strongly discouraged ๐Ÿšจ like bestie please don't.

for variables net.inet.*.ipsec, please refer to ipsec(4) ๐Ÿซถ

๐ŸŒ PF_INET6

Get or set various global info about IPv6 (Internet Protocol version 6) ๐Ÿ’œ. the third level name is the protocol, the fourth level name is the variable name.

For variables net.inet6.* please refer to inet6(4) โœจ. For variables net.inet6.*.ipsec6, please refer to ipsec(4).


๐Ÿ‘ค CTL_USER

the string and integer info available at the CTL_USER level is detailed below. the changeable column shows whether a process with appropriate privilege may change the value โ€” spoiler, none of these are changeable, they're all read-only queens ๐Ÿ‘‘:

  • 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_CS_PATH โ€” string โ€” no
  • USER_EXPR_NEST_MAX โ€” integer โ€” no
  • USER_LINE_MAX โ€” integer โ€” no
  • USER_LOCALBASE โ€” string โ€” no
  • USER_POSIX2_CHAR_TERM โ€” integer โ€” no
  • USER_POSIX2_C_BIND โ€” integer โ€” no
  • USER_POSIX2_C_DEV โ€” 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
  • USER_POSIX2_VERSION โ€” integer โ€” no
  • USER_RE_DUP_MAX โ€” integer โ€” no
  • USER_STREAM_MAX โ€” integer โ€” no
  • USER_TZNAME_MAX โ€” integer โ€” no

okay now the actual definitions, one by one ๐Ÿ’–:

๐Ÿงฎ USER_BC_BASE_MAX

The maximum ibase/obase values in the bc(1) utility.

๐Ÿงฎ USER_BC_DIM_MAX

The maximum array size in the bc(1) utility.

๐Ÿงฎ USER_BC_SCALE_MAX

The maximum scale value in the bc(1) utility.

๐Ÿงฎ USER_BC_STRING_MAX

The maximum string length in the bc(1) utility.

๐ŸŒ USER_COLL_WEIGHTS_MAX

The maximum number of weights that can be assigned to any entry of the LC_COLLATE order keyword in the locale definition file ๐Ÿฆ‹

๐Ÿ›ค๏ธ USER_CS_PATH

Return a value for the PATH environment variable that finds all the standard utilities โœจ

๐Ÿง  USER_EXPR_NEST_MAX

The maximum number of expressions that can be nested within parenthesis by the expr(1) utility. deep nesting? she said know your limits.

๐Ÿ“ USER_LINE_MAX

The maximum length in bytes of a text-processing utility's input line.

๐Ÿ“ฆ USER_LOCALBASE

Return the value of localbase that has been compiled into system utilities that need to have access to resources provided by a port or package ๐ŸŽ€

๐Ÿ–ฅ๏ธ USER_POSIX2_CHAR_TERM

Return 1 if the system supports at least one terminal type capable of all operations described in IEEE Std 1003.2 ("POSIX.2"), otherwise 0 ๐Ÿ’…

๐Ÿ–ฅ๏ธ USER_POSIX2_C_BIND

Return 1 if the system's C-language development facilities support the C-Language Bindings Option, otherwise 0 โœจ

๐Ÿ–ฅ๏ธ USER_POSIX2_C_DEV

Return 1 if the system supports the C-Language Development Utilities Option, otherwise 0 ๐ŸŒธ

๐Ÿ–ฅ๏ธ USER_POSIX2_FORT_DEV

Return 1 if the system supports the FORTRAN Development Utilities Option, otherwise 0 ๐Ÿ”ฅ

๐Ÿ–ฅ๏ธ USER_POSIX2_FORT_RUN

Return 1 if the system supports the FORTRAN Runtime Utilities Option, otherwise 0 โญ

๐Ÿ–ฅ๏ธ USER_POSIX2_LOCALEDEF

Return 1 if the system supports the creation of locales, otherwise 0 ๐ŸŒˆ

๐Ÿ–ฅ๏ธ USER_POSIX2_SW_DEV

Return 1 if the system supports the Software Development Utilities Option, otherwise 0 ๐Ÿ‘‘

๐ŸŒธ the user-level identifiers, continued ๐ŸŒธ

  • USER_POSIX2_UPE โ€” returns 1 if the system supports the User Portability Utilities Option, otherwise 0. yes bestie it's a vibe check for POSIX ๐Ÿ’…
  • USER_POSIX2_VERSION โ€” the version of IEEE Std 1003.2 (โ€œPOSIX.2โ€) that the system is attempting to comply with. key word attempting ๐Ÿ˜ญ
  • USER_RE_DUP_MAX โ€” the maximum number of repeated occurrences of a regular expression that's permitted when you're using interval notation. so like {n,m} energy ๐ŸŽ€
  • USER_STREAM_MAX โ€” the minimum maximum number of streams a process may have open at any one time. yes, "minimum maximum", it's giving oxymoron but it's real โœจ
  • USER_TZNAME_MAX โ€” the minimum maximum number of types supported for the name of a timezone. ๐Ÿ•ฐ๏ธ

๐Ÿ”ฅ CTL_VM ๐Ÿ”ฅ

okay so the string and integer info available at the CTL_VM level is all spelled out below, no gatekeeping. the changeable column tells you whether a process with appropriate privilege can actually change the value โ€” like, do you have the range to touch it or nah ๐Ÿ‘‘

  • VM_LOADAVG โ€” type struct loadavg, changeable: no
  • VM_TOTAL โ€” type struct vmtotal, changeable: no
  • VM_SWAPPING_ENABLED โ€” type integer, changeable: maybe
  • VM_V_FREE_MIN โ€” type integer, changeable: yes
  • VM_V_FREE_RESERVED โ€” type integer, changeable: yes
  • VM_V_FREE_TARGET โ€” type integer, changeable: yes
  • VM_V_INACTIVE_TARGET โ€” type integer, changeable: yes
  • VM_V_PAGEOUT_FREE_MIN โ€” type integer, changeable: yes
  • VM_OVERCOMMIT โ€” type integer, changeable: yes

the individual VM identifiers, one by one ๐Ÿ’œ

  • VM_LOADAVG โ€” returns the load average history. what you get back is a struct loadavg. history class for your CPU ๐Ÿ“ˆ
  • VM_TOTAL โ€” returns the system wide virtual memory statistics. what you get back is a struct vmtotal. the whole system's memory receipts ๐Ÿงพ
  • VM_SWAPPING_ENABLED โ€” 1 if process swapping is enabled, or 0 if it's disabled. tiny caveat bestie: this variable is permanently set to 0 if the kernel was built with swapping disabled. so no takebacks ๐Ÿ™ˆ
  • VM_V_FREE_MIN โ€” the minimum amount of memory (cache memory plus free memory) that has to be available before a process waiting on memory will get awakened. like the bare minimum to be let back in the group chat ๐Ÿ˜ด
  • VM_V_FREE_RESERVED โ€” processes will awaken the pageout daemon and wait for memory if the number of free and cached pages drops below this value. the panic button number ๐Ÿšจ
  • VM_V_FREE_TARGET โ€” the total amount of free memory (cache memory included) that the pageout daemon tries to maintain. its little goal in life ๐ŸŽฏ
  • VM_V_INACTIVE_TARGET โ€” the desired number of inactive pages the pageout daemon should achieve when it runs. inactive pages can be quickly inserted into process address space when needed, so it's lowkey a stash ๐Ÿ—‚๏ธ
  • VM_V_PAGEOUT_FREE_MIN โ€” if the amount of free and cache memory falls below this value, the pageout daemon enters "memory conserving mode" to avoid deadlock. emergency era ๐Ÿ’€
  • VM_OVERCOMMIT โ€” overcommit behaviour, as described in tuning(7). go read that one for the tea ๐Ÿต

โœจ RETURN VALUES โœจ

upon successful completion, the value 0 is returned. otherwise the value -1 is returned and the global variable errno is set to indicate the error. classic zero-or-negative-one situation, no in between ๐Ÿซถ


๐ŸŽ€ FILES ๐ŸŽ€

  • <sys/sysctl.h> โ€” definitions for top level identifiers, second level kernel and hardware identifiers, and user level identifiers
  • <sys/socket.h> โ€” definitions for second level network identifiers
  • <sys/gmon.h> โ€” definitions for third level profiling identifiers
  • <vm/vm_param.h> โ€” definitions for second level virtual memory identifiers
  • <netinet/in.h> โ€” definitions for third level IPv4/IPv6 identifiers and fourth level IPv4/v6 identifiers
  • <netinet/icmp_var.h> โ€” definitions for fourth level ICMP identifiers
  • <netinet/icmp6.h> โ€” definitions for fourth level ICMPv6 identifiers
  • <netinet/udp_var.h> โ€” definitions for fourth level UDP identifiers

๐Ÿ’€ ERRORS ๐Ÿ’€

these are the errors that may be reported, read them like a warning label bestie:

  • [EFAULT] โ€” the buffer name, oldp, newp, or length pointer oldlenp contains an invalid address.
  • [EINVAL] โ€” the name array is less than two or greater than CTL_MAXNAME.
  • [EINVAL] โ€” a non-null newp is given and its specified length in newlen is too large or too small.
  • [ENOMEM] โ€” the length pointed to by oldlenp is too short to hold the requested value.
  • [ENOMEM] โ€” the smaller of either the length pointed to by oldlenp or the estimated size of the returned data exceeds the system limit on locked memory.
  • [ENOMEM] โ€” locking the buffer oldp, or a portion of the buffer if the estimated size of the data to be returned is smaller, would cause the process to exceed its per-process locked memory limit.
  • [ENOTDIR] โ€” the name array specifies an intermediate rather than terminal name.
  • [EISDIR] โ€” the name array specifies a terminal name, but the actual name is not terminal.
  • [ENOENT] โ€” the name array specifies a value that is unknown.
  • [EPERM] โ€” an attempt is made to set a read-only value. rude honestly ๐Ÿ™„
  • [EPERM] โ€” a process without appropriate privilege attempts to set a value. no privilege, no entry, that's the rule ๐Ÿ’…

๐ŸŒˆ SEE ALSO ๐ŸŒˆ

confstr(3), kinfo_getproc(3), kvm(3), sysconf(3), sysctl(8)


โญ HISTORY โญ

the sysctl() function first appeared in 4.4BSD. an icon, a legend, a pioneer ๐Ÿ‘‘


and that's the whole page bestie, you ate that ๐Ÿซถ this one's from the Debian crew, dated July 31, 2025, and it's SYSCTL(3) โ€” go forth and sysctl responsibly โœจ๐Ÿ’–

๐Ÿ“ฆ where this page comes from
  • freebsd 15.1: base 15.1
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms