SYSCTL(2) | Linux Programmer's Manual | SYSCTL(2) |
sysctl - システムパラメーターを読み書きする
#include <unistd.h> #include <linux/sysctl.h>
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; /* 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)を検索する。 そして、要求された項目が見つかった場合は適切なルーチンを呼び出して 値を読んだり修正したりする。
成功した場合は _sysctl() は 0 を返す。失敗した場合、-1 が返され、 errno がそのエラーを示す値に設定される。
This system call first appeared in Linux 1.3.57. It was removed in Linux 5.5; glibc support was removed in version 2.32.
このコールは Linux 特有であり、移植を意図したプログラムで使用しては いけない。これは 4.4BSD に由来している。Linux は /proc/sys に写し(mirror)をもっており、項目の名前の付け方が Linux と 4.4BSD では 異っている。しかし sysctl() 関数の宣言は両方で同じである。
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 <unistd.h> #include <sys/syscall.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <linux/sysctl.h> int _sysctl(struct __sysctl_args *args ); #define OSNAMESZ 100 int main(void) { struct __sysctl_args args; char osname[OSNAMESZ]; size_t osnamelth; int name[] = { CTL_KERN, KERN_OSTYPE }; memset(&args, 0, sizeof(args)); args.name = name; args.nlen = sizeof(name)/sizeof(name[0]); 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", osnamelth, osname); exit(EXIT_SUCCESS); }
proc(5)
この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。
2020-11-01 | Linux |