1SYSCTL(2)                  Linux Programmer's Manual                 SYSCTL(2)
2
3
4

NAME

6       sysctl - read/write system parameters
7

SYNOPSIS

9       #include <unistd.h>
10       #include <linux/sysctl.h>
11
12       int _sysctl(struct __sysctl_args *args);
13

DESCRIPTION

15       This system call no longer exists on current kernels!  See NOTES.
16
17       The _sysctl() call reads and/or writes kernel parameters.  For example,
18       the hostname, or the maximum number of open files.   The  argument  has
19       the form
20
21           struct __sysctl_args {
22               int    *name;    /* integer vector describing variable */
23               int     nlen;    /* length of this vector */
24               void   *oldval;  /* 0 or address where to store old value */
25               size_t *oldlenp; /* available room for old value,
26                                   overwritten by actual size of old value */
27               void   *newval;  /* 0 or address of new value */
28               size_t  newlen;  /* size of new value */
29           };
30
31       This  call does a search in a tree structure, possibly resembling a di‐
32       rectory tree under /proc/sys, and if the requested item is found  calls
33       some appropriate routine to read or modify the value.
34

RETURN VALUE

36       Upon successful completion, _sysctl() returns 0.  Otherwise, a value of
37       -1 is returned and errno is set to indicate the error.
38

ERRORS

40       EACCES, EPERM
41              No search permission for one of the  encountered  "directories",
42              or no read permission where oldval was nonzero, or no write per‐
43              mission where newval was nonzero.
44
45       EFAULT The invocation asked for the previous value  by  setting  oldval
46              non-NULL, but allowed zero room in oldlenp.
47
48       ENOTDIR
49              name was not found.
50

VERSIONS

52       This  system  call  first  appeared in Linux 1.3.57.  It was removed in
53       Linux 5.5; glibc support was removed in version 2.32.
54

CONFORMING TO

56       This call is Linux-specific, and should not be  used  in  programs  in‐
57       tended  to  be  portable.  It originated in 4.4BSD.  Only Linux has the
58       /proc/sys mirror, and the object naming schemes  differ  between  Linux
59       and 4.4BSD, but the declaration of the sysctl() function is the same in
60       both.
61

NOTES

63       Use of this system call was long discouraged: since Linux 2.6.24,  uses
64       of  this system call result in warnings in the kernel log, and in Linux
65       5.5, the system call was finally removed.  Use the /proc/sys  interface
66       instead.
67
68       Note  that  on older kernels where this system call still exists, it is
69       available  only  if  the  kernel   was   configured   with   the   CON‐
70       FIG_SYSCTL_SYSCALL option.  Furthermore, glibc does not provide a wrap‐
71       per for this system call, necessitating the use of syscall(2).
72

BUGS

74       The object names vary between kernel versions, making this system  call
75       worthless for applications.
76
77       Not all available objects are properly documented.
78
79       It  is  not  yet  possible  to  change  operating  system by writing to
80       /proc/sys/kernel/ostype.
81

EXAMPLES

83       #define _GNU_SOURCE
84       #include <unistd.h>
85       #include <sys/syscall.h>
86       #include <string.h>
87       #include <stdio.h>
88       #include <stdlib.h>
89       #include <linux/sysctl.h>
90
91       int _sysctl(struct __sysctl_args *args );
92
93       #define OSNAMESZ 100
94
95       int
96       main(void)
97       {
98           struct __sysctl_args args;
99           char osname[OSNAMESZ];
100           size_t osnamelth;
101           int name[] = { CTL_KERN, KERN_OSTYPE };
102
103           memset(&args, 0, sizeof(args));
104           args.name = name;
105           args.nlen = sizeof(name)/sizeof(name[0]);
106           args.oldval = osname;
107           args.oldlenp = &osnamelth;
108
109           osnamelth = sizeof(osname);
110
111           if (syscall(SYS__sysctl, &args) == -1) {
112               perror("_sysctl");
113               exit(EXIT_FAILURE);
114           }
115           printf("This machine is running %*s\n", osnamelth, osname);
116           exit(EXIT_SUCCESS);
117       }
118

SEE ALSO

120       proc(5)
121

COLOPHON

123       This page is part of release 5.10 of the Linux  man-pages  project.   A
124       description  of  the project, information about reporting bugs, and the
125       latest    version    of    this    page,    can     be     found     at
126       https://www.kernel.org/doc/man-pages/.
127
128
129
130Linux                             2020-11-01                         SYSCTL(2)
Impressum