sysctl(2) System Calls Manual sysctl(2) sysctl - / #include #include [[deprecated]] int _sysctl(struct __sysctl_args *args); ! . _sysctl() / . . struct __sysctl_args { int *name; /* */ int nlen; /* */ void *oldval; /* 0 */ size_t *oldlenp; /* , */ void *newval; /* 0 */ size_t newlen; /* */ }; /proc/sys . _sysctl() 0. -1 errno . EACCES EPERM "" oldval newval . EFAULT oldval NULL oldlenp. ENOTDIR name. . 4.4BSD 1.3.57. 5.5 glibc 2.32. /proc/sys 4.4BSD sysctl() . : 2.6.24 5.5 . /proc/sys . CONFIG_SYSCTL_SYSCALL. glibc syscall(2). . . /proc/sys/kernel/ostype. #define _GNU_SOURCE #include #include #include #include #include #include #include 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); } proc(5) 3 . . : . 6.18 10 2026 sysctl(2)