OSDN Git Service

Update README
[linuxjm/LDP_man-pages.git] / release / man2 / sysctl.2
1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Written 11 April 1996 by Andries Brouwer <aeb@cwi.nl>
26 .\" 960412: Added comments from Stephen Tweedie
27 .\" Modified Tue Oct 22 22:28:41 1996 by Eric S. Raymond <esr@thyrsus.com>
28 .\" Modified Mon Jan  5 20:31:04 1998 by aeb.
29 .\"
30 .\"*******************************************************************
31 .\"
32 .\" This file was generated with po4a. Translate the source file.
33 .\"
34 .\"*******************************************************************
35 .\"
36 .\" Japanese Version Copyright (c) 1997-1998 HANATAKA Shinya
37 .\"         all rights reserved.
38 .\" Translated 1997-12-12, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
39 .\" Modified 1998-05-11, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
40 .\" Updated 2007-10-11, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.66
41 .\" Updated 2013-05-01, Akihiro MOTOKI <amotoki@gmail.com>
42 .\"
43 .TH SYSCTL 2 2012\-12\-22 Linux "Linux Programmer's Manual"
44 .SH 名前
45 sysctl \- システムパラメーターを読み書きする
46 .SH 書式
47 .nf
48 \fB#include <unistd.h>\fP
49 .br
50 \fB#include <linux/sysctl.h>\fP
51 .sp
52 \fBint _sysctl(struct __sysctl_args *\fP\fIargs\fP\fB);\fP
53 .fi
54
55 \fI注\fP: このシステムコールには glibc のラッパー関数は存在しない。「注意」の節を参照。
56 .SH 説明
57 \fBこのシステムコールを使用しないこと!\fP 「注意」の節を参照。
58
59 \fB_sysctl\fP()  コールはカーネルパラメーターを読み書きする。例えば、 ホストネームや同時にオープンできるファイルの最大数など。
60 引き数は以下の形式である。
61 .PP
62 .in +4n
63 .nf
64 struct __sysctl_args {
65     int    *name;    /* integer vector describing variable */
66     int     nlen;    /* length of this vector */
67     void   *oldval;  /* 0 or address where to store old value */
68     size_t *oldlenp; /* available room for old value,
69                         overwritten by actual size of old value */
70     void   *newval;  /* 0 or address of new value */
71     size_t  newlen;  /* size of new value */
72 };
73 .fi
74 .in
75 .PP
76 このコールは \fI/proc/sys\fP の下のディレクトリツリーに似た木構造(tree structure)を検索する。
77 そして、要求された項目が見つかった場合は適切なルーチンを呼び出して 値を読んだり修正したりする。
78 .SH 返り値
79 成功した場合は \fB_sysctl\fP()  は 0 を返す。失敗した場合、\-1 が返され、 \fIerrno\fP がそのエラーを示す値に設定される。
80 .SH エラー
81 .TP 
82 \fBEFAULT\fP
83 \fIoldval\fP に NULL でない値を設定して、以前の値を要求しているのに、 \fIoldlenp\fP に空きがない。
84 .TP 
85 \fBENOTDIR\fP
86 \fIname\fP が見つからなかった。
87 .TP 
88 \fBEACCES\fP か \fBEPERM\fP
89 「ディレクトリ」のどれかに検索許可がなかったか、 \fIoldval\fP が 0 でないのに読み込み許可がなかったか、 \fInewval\fP が 0
90 でないのに書き込み許可がなかった。
91 .SH 準拠
92 このコールは Linux 特有であり、移植を意図したプログラムで使用しては いけない。 \fBsysctl\fP()  コールは Linux のバージョン
93 1.3.57 から存在している。 これは 4.4BSD に由来している。Linux は \fI/proc/sys\fP
94 に写し(mirror)をもっており、項目の名前の付け方が Linux と 4.4BSD では 異っている。しかし \fBsysctl\fP()
95 関数の宣言は両方で同じである。
96 .SH 注意
97 .\" See http://lwn.net/Articles/247243/
98 .\" Though comments in suggest that it is needed by old glibc binaries,
99 .\" so maybe it's not going away.
100 glibc はこのシステムコールに対するラッパー関数を提供していない。 \fBsyscall\fP(2)
101 を使って呼び出すこと。というよりは・・・このシステムコールを呼び出さないこと。 長い間このシステムコールの使用は非推奨とされており、
102 「将来のバージョンのカーネルで削除されるようだ」と言われるほどである。 あなたのプログラムにこのシステムコールがあれば、すぐにでも削除すること。
103 代わりに \fI/proc/sys\fP インターフェースを使用すること。
104
105 このシステムコールは、カーネルの \fBCONFIG_SYSCTL_SYSCALL\fP オプションが有効になっている場合のみ利用できる。
106 .SH バグ
107 オブジェクトの名前は、カーネルのバージョンごとに異なっている。 このため、このシステムコールはアプリケーションにとって 無価値なものとなっている。
108 .PP
109 全ての可能な項目が正確に記述されているわけではない。
110 .PP
111 今のところ \fI/proc/sys/kernel/ostype\fP に書き込むことでオペーレーティングシステムを変えることはできない。
112 .SH 例
113 .nf
114 #define _GNU_SOURCE
115 #include <unistd.h>
116 #include <sys/syscall.h>
117 #include <string.h>
118 #include <stdio.h>
119 #include <stdlib.h>
120 #include <linux/sysctl.h>
121
122 int _sysctl(struct __sysctl_args *args );
123
124 #define OSNAMESZ 100
125
126 int
127 main(void)
128 {
129     struct __sysctl_args args;
130     char osname[OSNAMESZ];
131     size_t osnamelth;
132     int name[] = { CTL_KERN, KERN_OSTYPE };
133
134     memset(&args, 0, sizeof(struct __sysctl_args));
135     args.name = name;
136     args.nlen = sizeof(name)/sizeof(name[0]);
137     args.oldval = osname;
138     args.oldlenp = &osnamelth;
139
140     osnamelth = sizeof(osname);
141
142     if (syscall(SYS__sysctl, &args) == \-1) {
143         perror("_sysctl");
144         exit(EXIT_FAILURE);
145     }
146     printf("This machine is running %*s\en", osnamelth, osname);
147     exit(EXIT_SUCCESS);
148 }
149 .fi
150 .SH 関連項目
151 \fBproc\fP(5)
152 .SH この文書について
153 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部
154 である。プロジェクトの説明とバグ報告に関する情報は
155 http://www.kernel.org/doc/man\-pages/ に書かれている。