Unix-system-calls--syscall
[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| == _syscall()-Unix、Linuxシステムコール
[[File:]] image :http://www.finddevguides.com/images/next.gif [next] image:http://www.finddevguides.com/add- this.gif [AddThisソーシャルブックマークボタン]
広告
NAME
_syscall-ライブラリサポートなしのシステムコールの呼び出し(OBSOLETE)
概要
#include <linux/unistd.h> A _syscall macro desired system call |
説明
システムコールについて知っておくべき重要なことは、そのプロトタイプです。 引数の数、型、および関数の戻り値の型を知る必要があります。 システムへの実際の呼び出しを容易にする7つのマクロがあります。 それらの形式は次のとおりです。
_syscallX(type,name,type1,arg1,type2,arg2,...) |
どこで
Tag | Description |
---|---|
X | is 0-6, which are the number of arguments taken by the system call |
type | is the return type of the system call |
name | is the name of the system call |
typeN | is the Nth argument’s type |
argN | is the name of the Nth argument |
これらのマクロは、指定した引数で_name_という関数を作成します。 ソースファイルに_syscall()を含めると、_name_によってシステムコールを呼び出します。
ファイル
/usr/include/linux/unistd.h
準拠
これらのマクロの使用はLinux固有であり、非推奨です。
ノート
カーネル2.6.18前後から、_syscallマクロはユーザー空間に提供されるヘッダーファイルから削除されました。 代わりに syscall (2)を使用してください。 (一部のアーキテクチャ、特にia64は、_syscallマクロを提供していません。これらのアーキテクチャでは、 syscall (2)が常に必要でした。)
_syscall()マクロは、プロトタイプを作成しません。 特にC ++ユーザーの場合は、作成する必要があります。
システムコールは、正または負のエラーコードのみを返す必要はありません。 エラーを返す方法を確認するには、ソースを読む必要があります。 通常、これは標準エラーコードのマイナスです(例:- EPERM )。 _syscall()マクロは、_r_が負でない場合はシステムコールの結果_r_を返しますが、-1を返し、_r_が負の場合は変数_errno_を-_r_に設定します。 エラーコードについては、 errno (3)を参照してください。
システムコールを定義するとき、引数タイプは値またはポインタ(構造体のような集合体の場合)で渡される必要があります。
例
#include <stdio.h> #include <stdlib.h> #include <errno.h> #include <linux/unistd.h> #include <linux/kernel.h> _syscall1(int, sysinfo, struct sysinfo *, info); /*Note: if you copy directly from the nroff source, remember to REMOVE the extra backslashes in the printf statement.*/ int main(void) { struct sysinfo s_info; int error; error = sysinfo(&s_info); printf("code error = %d\n", error); printf("Uptime = %lds\nLoad: 1 min %lu/5 min %lu/15 min %lu\n" "RAM: total %lu/free %lu/shared %lu\n" "Memory in buffers = %lu\nSwap: total %lu/free %lu\n" "Number of processes = %d\n", s_info.uptime, s_info.loads[0], s_info.loads[1], s_info.loads[2], s_info.totalram, s_info.freeram, s_info.sharedram, s_info.bufferram, s_info.totalswap, s_info.freeswap, s_info.procs); exit(EXIT_SUCCESS); } |
出力例
code error = 0 uptime = 502034s Load: 1 min 13376/5 min 5504/15 min 1152 RAM: total 15343616/free 827392/shared 8237056 Memory in buffers = 5066752 Swap: total 27881472/free 24698880 Number of processes = 40 |
関連項目
[[File:]] image :http://www.finddevguides.com/images/next.gif [next] [[File:]]
広告
|
[cols="^",] |
|Advertisements