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 ๐Ÿ‘‘

  • EACCES
  • EPERM โ€” no search permission for one of the encountered "directories", or no read permission where oldval was nonzero, or no write permission where newval was nonzero. (the quotes around "directories" are the original's, and honestly they ate ๐Ÿ’€)
  • EFAULT โ€” the invocation asked for the previous value by setting oldval non-NULL, but allowed zero room in oldlenp. rude of you, honestly.
  • ENOTDIR โ€” name was 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 in Linux 5.5, glibc 2.32.
  • Only Linux has the /proc/sys mirror, and the object naming schemes differ between Linux and 4.4BSD, but the declaration of the sysctl() 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms