sysctl(2)
๐ sysctl(2) โ the "read/write system parameters" girlie ๐
okay bestie, pull up a chair, because this is the sysctl system call page from section 2 (the System Calls Manual, yes we're in the syscall girlies' territory โจ). I need you to know upfront: this one is a history lesson, not a "go use this right now" situation. She's retired. She's an icon. She no longer exists on current kernels. Let's get into it ๐
๐ธ NAME ๐ธ
sysctl โ read/write system parameters
โจ SYNOPSIS โจ
#include <unistd.h>
#include <linux/sysctl.h>
[[deprecated]] int _sysctl(struct __sysctl_args *args);
not the [[deprecated]] tag already showing up in the synopsis... she is literally telling on herself ๐ญ
๐ฆ DESCRIPTION ๐ฆ
This system call no longer exists on current kernels! See NOTES. (yes, in the original it's an exclamation point, they were stressed.)
The _sysctl() call reads and/or writes kernel parameters. Like, for example, the hostname, or the maximum number of open files. Classic system-parameter vibes.
The argument has the form
struct __sysctl_args {
int *name; /* integer vector describing variable */
int nlen; /* number of elements of this vector */
void *oldval; /* 0 or address where to store old value */
size_t *oldlenp; /* available room for old value,
overwritten by actual size of old value */
void *newval; /* 0 or address of new value */
size_t newlen; /* size of new value */
};
So the whole thing is: this call does a search in a tree structure, possibly resembling a directory tree under /proc/sys, and if the requested item is found, it calls some appropriate routine to read or modify the value. cute. tree-shaped. very demure.
๐ซถ RETURN VALUE ๐ซถ
Upon successful completion, _sysctl() returns 0. Otherwise, a value of -1 is returned and errno is set to indicate the error. standard behavior, no notes โ
๐ ERRORS ๐
EACCESEPERMโ no search permission for one of the encountered "directories", or no read permission whereoldvalwas nonzero, or no write permission wherenewvalwas nonzero. (the quotes around "directories" are the original's, and honestly they ate ๐)EFAULTโ the invocation asked for the previous value by settingoldvalnon-NULL, but allowed zero room inoldlenp. rude of you, honestly.ENOTDIRโnamewas not found.
๐ STANDARDS ๐
Linux. that's it. that's the whole section. she's Linux-only and she's not apologizing ๐ซก
๐ HISTORY ๐
4.4BSD,Linux 1.3.57. Removed inLinux 5.5,glibc 2.32.- Only Linux has the
/proc/sysmirror, and the object naming schemes differ between Linux and 4.4BSD, but the declaration of thesysctl()function is the same in both. so like... cousins. distant cousins. same signature, different lore.
๐ NOTES ๐
Use of this system call was long discouraged: since Linux 2.6.24, uses of this system call result in warnings in the kernel log, and in Linux 5.5, the system call was finally removed. Use the /proc/sys interface instead. that's the glow-up, babes โ /proc/sys is the moment.
Note that on older kernels where this system call still exists, it is available only if the kernel was configured with the CONFIG_SYSCTL_SYSCALL option. Furthermore, glibc does not provide a wrapper for this system call, necessitating the use of syscall(2). so you had to rawdog it through syscall(2). no wrapper, no comfort, no hand-holding ๐ญ
๐ BUGS ๐
- The object names vary between kernel versions, making this system call worthless for applications. worthless, the manpage said it, not me ๐
- Not all available objects are properly documented.
- It is not yet possible to change operating system by writing to
/proc/sys/kernel/ostype. bestie you cannot just declare a new OS. unfortunately.
๐ EXAMPLES ๐
here's the whole demo, verbatim, no edits, we respect the code:
#define _GNU_SOURCE
#include <stdcountof.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <linux/sysctl.h>
int _sysctl(struct __sysctl_args *args);
#define OSNAMESZ 100
int
main(void)
{
int name[] = { CTL_KERN, KERN_OSTYPE };
char osname[OSNAMESZ];
size_t osnamelth;
struct __sysctl_args args;
memset(&args, 0, sizeof(args));
args.name = name;
args.nlen = countof(name);
args.oldval = osname;
args.oldlenp = &osnamelth;
osnamelth = sizeof(osname);
if (syscall(SYS__sysctl, &args) == -1) {
perror("_sysctl");
exit(EXIT_FAILURE);
}
printf("This machine is running %*s\n", (int) osnamelth, osname);
exit(EXIT_SUCCESS);
}
she's asking the kernel what OS this is. which, given the BUGS section, is a whole journey. anyway, slay ๐ง
โญ SEE ALSO โญ
proc(5)โ the one that actually matters now, fr fr
and that's the page, bestie. this was sysctl(2) from Linux man-pages 6.20, dated 2026-02-10. go forth, use /proc/sys, and let _sysctl() rest in peace ๐๏ธ it's giving retired legend energy and we love her for it ๐โจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1996, Andries E. Brouwer <aeb@cwi.nl>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms