Seth Woolley's Man Viewer

Manual for sysctl - man 2 sysctl

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

SYSCTL(2)                  Linux Programmer's Manual                 SYSCTL(2)



NAME
       sysctl(2,5,8) - read(2,n,1 builtins)/write(1,2) system parameters

SYNOPSIS
       #include <unistd.h>

       #include <linux/unistd.h>

       #include <linux/sysctl.h>

       _syscall1(int, _sysctl, struct __sysctl_args *, args);

       int _sysctl(struct __sysctl_args *args);

DESCRIPTION
       The  _sysctl  call  reads and/or writes kernel parameters. For example,
       the hostname, or the maximum number of open(2,3,n) files. The argument has the
       form

       struct __sysctl_args {
               int *name;        /* integer vector describing variable */
               int nlen;         /* length 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 */
       };

       This  call  does  a  search  in(1,8) a tree structure, possibly resembling a
       directory tree under /proc(5,n)/sys, and if(3,n)  the  requested  item  is  found
       calls some appropriate routine to read(2,n,1 builtins) or modify the value.


EXAMPLE
       #include <linux/unistd.h>
       #include <linux/types.h>
       #include <linux/sysctl.h>

       _syscall1(int, _sysctl, struct __sysctl_args *, args);
       int sysctl(2,5,8)(int *name, int nlen, void *oldval, size_t *oldlenp,
                  void *newval, size_t newlen)
       {
               struct __sysctl_args args={name,nlen,oldval,oldlenp,newval,newlen};
               return _sysctl(&args);
       }

       #define SIZE(x) sizeof(x)/sizeof(x[0])
       #define OSNAMESZ 100

       char osname[OSNAMESZ];
       int osnamelth;
       int name[] = { CTL_KERN, KERN_OSTYPE };

       main(){
               osnamelth = sizeof(osname);
               if(3,n) (sysctl(2,5,8)(name, SIZE(name), osname, &osnamelth, 0, 0))
                       perror(1,3)("sysctl(2,5,8)");
               else
                       printf(1,3,1 builtins)("This machine is running %*s\n", osnamelth, osname);
               return 0;
       }


RETURN VALUE
       Upon successful completion, _sysctl returns 0. Otherwise, a value of -1
       is returned and errno is set(7,n,1 builtins) to indicate the error.

ERRORS
       EFAULT The invocation asked for the previous value  by  setting  oldval
              non-NULL, but allowed zero room in(1,8) oldlenp.

       ENOTDIR
              name was not found.

       EPERM  No  search  permission for one of the encountered `directories',
              or no read(2,n,1 builtins) permission where oldval was nonzero, or no write(1,2) per-
              mission where newval was nonzero.

CONFORMING TO
       This  call  is  Linux-specific,  and  should  not  be  used in(1,8) programs
       intended to be portable.  A sysctl(2,5,8) call has been present in(1,8) Linux since
       version(1,3,5)  1.3.57.  It originated in(1,8) 4.4BSD. Only Linux has the /proc(5,n)/sys
       mirror, and the object naming schemes differ between Linux and BSD 4.4,
       but the declaration of the sysctl(2,5,8)(2) function is the same in(1,8) both.

BUGS
       The  object names vary between kernel versions.  THIS MAKES THIS SYSTEM
       CALL WORTHLESS FOR APPLICATIONS.  Use the /proc(5,n)/sys interface  instead.
       Not all available objects are properly documented.
       It  is  not  yet  possible  to  change  operating  system by writing to
       /proc(5,n)/sys/kernel/ostype.

SEE ALSO
       proc(5,n)(5)



Linux 1.3.85                      1996-04-11                         SYSCTL(2)

References for this manual (incoming links)