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
14       Note: There is no glibc wrapper for this system call; see NOTES.
15

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

CONFORMING TO

54       This  call  is  Linux-specific,  and  should  not  be  used in programs
55       intended to be portable.  A sysctl() call has  been  present  in  Linux
56       since  version  1.3.57.   It  originated in 4.4BSD.  Only Linux has the
57       /proc/sys mirror, and the object naming schemes  differ  between  Linux
58       and 4.4BSD, but the declaration of the sysctl() function is the same in
59       both.
60

NOTES

62       Glibc does not provide a wrapper for this system call;  call  it  using
63       syscall(2).   Or  rather...  don't call it: use of this system call has
64       long been discouraged, and it is so unloved that it is likely to disap‐
65       pear in a future kernel version.  Since Linux 2.6.24, uses of this sys‐
66       tem call result in warnings in the kernel log.   Remove  it  from  your
67       programs now; use the /proc/sys interface instead.
68
69       This  system  call  is available only if the kernel was configured with
70       the CONFIG_SYSCTL_SYSCALL option.
71

BUGS

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

EXAMPLE

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

SEE ALSO

119       proc(5)
120

COLOPHON

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