sysctl

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



åå
       sysctl - ã·ã¹ãã ã»ãã©ã¡ã¼ã¿ã¼ãèªã¿æ¸ããã

æ¸å¼
       #include <unistd.h>

       #include <linux/unistd.h>

       #include <linux/sysctl.h>

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

       int _sysctl(struct __sysctl_args *args);

説æ
       _sysctl ã³ã¼ã«ã¯ã«ã¼ãã«(kernel)ãã©ã¡ã¼ã¿ã¼ãèªã¿æ¸ããããä¾ãã°ã
       ãã¹ããã¼ã (hostname)ãåæã«éã(open)ãã¨ãã§ãããã¡ã¤ã«ã®æ大æ°ãªã©ã
       å¼ãæ°ã¯ä»¥ä¸ã®å½¢å¼ã§ããã

       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 */
       };

       ãã®ã³ã¼ã«ã¯ /proc/sys ã®ä¸ã®ãã£ã¬ã¯ããªã»ããªã¼ã«ä¼¼ãæ¨æ§é (tree
       structure)ãæ¤ç´¢ããã
       ããã¦ãè¦æ±ãããé ç®ãè¦ã¤ãã£ãå ´åã¯é©åãªã«ã¼ãã³ãå¼ã³åºã㦠å¤ãèªãã ãä¿®æ‐
       £ãããããã


ä¾
       #include <linux/unistd.h>
       #include <linux/types.h>
       #include <linux/sysctl.h>

       _syscall1(int, _sysctl, struct __sysctl_args *, args);
       int sysctl(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 = SIZE(osname);
               if (sysctl(name, SIZE(name), osname, &osnamelth, 0, 0))
                       perror("sysctl");
               else
                       printf("This machine is running %*s\n", osnamelth, osname);
               return 0;
       }


è¿ãå¤
       æåããå ´å㯠_sysctl 㯠0 ãè¿ããããã§ãªããã°ãå¤ã¨ã㦠-1 ãè¿ããã errno
       ããã®ã¨ã©ã¼ã示ãå¤ã«è¨å®ãããã

ã¨ã©ã¼
       ENOTDIR
              name ãè¦ã¤ãããªãã£ãã

       EPERM
               'ãã£ã¬ã¯ããª'ã®ã©ããã«æ¤ç´¢è¨±å¯ããªãã£ããã oldval ãã¼ãã§ãªãã®ã«èª‐
              ã¿è¾¼ã¿è¨±å¯ããªãã£ããã newval ãã¼ãã§ãªãã®ã«æ¸ãè¾¼ã¿è¨±å¯ããªãã£ãã

       EFAULT oldval ã« NULL ã§ãªãå¤ãè¨å®ãã¦ã以åã®å¤ãè¦æ±ãã¦ããã®ã«ã oldlenp
              ã«ç©ºãããªãã

æºæ
       ãã®ã³ã¼ã«ã¯ Linux ç¹æã§ããã移æ¤ãæå³ããããã°ã©ã ã§ä½¿ç¨ãã¦ã¯ ãããªãã

å±¥æ´
       sysctl ã³ã¼ã«ã¯ Linux ã®ãã¼ã¸ã§ã³ 1.3.57 ããåå¨ãã¦ããã ãã㯠4.4BSD
       ã«ç±æ¥ãã¦ãããLinux 㯠/proc/sys ã«åã(mirror)ããã£ã¦ãããé ç®ã®ååã®ä»ãæ¹ã
       Linux 㨠BSD 4.4 ã§ã¯ ç°ã£ã¦ãããããã sysctl(2)
       é¢æ°ã®å®£è¨ã¯ä¸¡æ¹ã¨ãåãã§ããã

ãã°
       å¨ã¦ã®å¯è½ãªé ç®ãæ£ç¢ºã«è¨è¿°ããã¦ããããã§ã¯ãªãã
       ä»ã®ã¨ã㨠/proc/sys/kernel/ostype
       ã«æ¸ãè¾¼ããã¨ã§ãªãã¼ã¬ã¼ãã£ã³ã°ã»ã·ã¹ãã ãå¤ãããã¨ã¯ã§ããªãã


é¢é£é ç®
       proc(5).



Linux 1.3.85                     11 April 1996                       SYSCTL(2)