sysctl(2) System Calls Manual sysctl(2) sysctl - / #include #include [[deprecated]] int _sysctl(struct __sysctl_args *args); This system call no longer exists on current kernels! See NOTES. _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 -NULL oldval, oldlenp . ENOTDIR name . Linux. Linux 1.3.57. Removed in Linux 5.5, glibc 2.32. It originated in 4.4BSD. 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. 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. 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). , . . /proc/sys/kernel/ostype. #define _GNU_SOURCE #include #include #include #include #include #include #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 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 = ARRAY_SIZE(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) Alexander Golubev , Azamat Hackimov , Hotellook, Nikita , Spiros Georgaras , Vladislav , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . sysctl(2)