sysctl

Section: System Calls (2)
Updated: 2026-02-10
Index JM Home Page roff page
 

名前

sysctl - システムパラメーターを読み書きする  

書式

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

[[deprecated]] int _sysctl(struct __sysctl_args *args);
 

説明

This system call no longer exists on current kernels! See NOTES.

_sysctl() コールはカーネルパラメーターを読み書きする。例えば、 ホストネームや同時にオープンできるファイルの最大数など。 引数は以下の形式である。

struct __sysctl_args {
    int    *name;    /* integer vector describing variable */
    int     nlen;    /* number of elements 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)を検索する。 そして、要求された項目が見つかった場合は適切なルーチンを呼び出して 値を読んだり修正したりする。  

返り値

成功した場合は _sysctl() は 0 を返す。失敗した場合、-1 が返され、 errno がそのエラーを示す値に設定される。  

エラー

EACCES
EPERM
「ディレクトリ」のどれかに検索許可がなかったか、 oldval が 0 でないのに読み込み許可がなかったか、 newval が 0 でないのに書き込み許可がなかった。
EFAULT
oldval に NULL でない値を設定して、以前の値を要求しているのに、 oldlenp に空きがない。
ENOTDIR
name が見つからなかった。
 

標準規格

Linux.  

歴史

4.4BSD, Linux 1.3.57. Removed in Linux 5.5, glibc 2.32.

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 <stdcountof.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>

#include <linux/sysctl.h>

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 = countof(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)


 

Index

名前
書式
説明
返り値
エラー
標準規格
歴史
注意
バグ
例
関連項目

This document was created by man2html, using the manual pages.