Unix-system-calls--sysctl
[top]#
|http://www.google.com/[Google] | a|
Web | This Site |
選択した読書
Copyright©2014 by finddevguides |
[cols=",,,,,,,",] |
| | Home | | References | | Discussion Forums | | About TP
[width="100%",cols="100%",] |
a| == sysctl()-Unix、Linuxシステムコール
[[File:]] image :http://www.finddevguides.com/images/next.gif [next] image:http://www.finddevguides.com/add- this.gif [AddThisソーシャルブックマークボタン]
広告
NAME
sysctl-システムパラメータの読み取り/書き込み
概要
#include <unistd.h> #include <linux/sysctl.h> int _sysctl(struct __sysctl_args* args); |
説明
- _ 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_の下のディレクトリツリーに似たツリー構造で検索を行い、要求されたアイテムが見つかった場合、適切なルーチンを呼び出して値を読み取りまたは変更します。
返り値
正常に完了すると、 _ sysctl ()は0を返します。 それ以外の場合、-1の値が返され、_errno_がエラーを示すために設定されます。
エラー
Tag | Description |
---|---|
EFAULT | The invocation asked for the previous value by settingoldval non-NULL, but allowed zero room in oldlenp. |
ENOTDIR | name was not found. |
EPERM | No search permission for one of the encountered ‘directories’,or no read permission where oldval was non-zero, or no write permission where newval was non-zero. |
準拠
この呼び出しはLinux固有であり、移植を目的としたプログラムでは使用しないでください。 Linuxでは、バージョン1.3.57以降、 sysctl ()呼び出しが存在します。
それは4.4BSDで始まりました。 Linuxにのみ_/proc/sys_ミラーがあり、オブジェクトの命名スキームはLinuxと4.4BSDで異なりますが、 sysctl (2)関数の宣言は両方で同じです。
BUGS
オブジェクト名はカーネルのバージョンによって異なります。 これにより、このシステムはアプリケーションの無駄になります。 代わりに_/proc/sys_インターフェイスを使用してください。
_/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(struct __sysctl_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); } |
ノート
Glibcはこのシステムコールのラッパーを提供しません。 syscall (2)を使用して呼び出します。
[[File:]] image :http://www.finddevguides.com/images/next.gif [next] [[File:]]
広告
|
[cols="^",] |
|Advertisements