OSDN Git Service

(split) LDP: Update the version to 3.53 in PO files
[linuxjm/LDP_man-pages.git] / release / man3 / system.3
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
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 .\" Modified Sat Jul 24 17:51:15 1993 by Rik Faith (faith@cs.unc.edu)
26 .\" Modified 11 May 1998 by Joseph S. Myers (jsm28@cam.ac.uk)
27 .\" Modified 14 May 2001, 23 Sep 2001 by aeb
28 .\" 2004-12-20, mtk
29 .\"
30 .\"*******************************************************************
31 .\"
32 .\" This file was generated with po4a. Translate the source file.
33 .\"
34 .\"*******************************************************************
35 .TH SYSTEM 3 2010\-09\-10 "" "Linux Programmer's Manual"
36 .SH 名前
37 system \- シェルコマンドの実行
38 .SH 書式
39 .nf
40 \fB#include <stdlib.h>\fP
41 .sp
42 \fBint system(const char *\fP\fIcommand\fP\fB);\fP
43 .fi
44 .SH 説明
45 \fBsystem\fP()  は \fIcommand\fP で指定したコマンドを \fB/bin/sh \-c\fP \fIcommand\fP
46 の形で実行する。指定したコマンドが終了すればこの関数も終了する。 コマンド実行中は、 \fBSIGCHLD\fP はブロックされ、 \fBSIGINT\fP と
47 \fBSIGQUIT\fP は無視される。
48 .SH 返り値
49 エラーが発生した場合 (\fBfork\fP(2)  に失敗した場合など)、\-1 を返す。 そうでなければ、コマンドのステータスを返す。
50 後者の場合、ステータスは \fBwait\fP(2)  で定義されているフォーマットで返ってくる。 従って、コマンドの終了コードは
51 \fIWEXITSTATUS(status)\fP で得ることが出来る。 \fI/bin/sh\fP が実行出来なかった場合、 終了ステータスはコマンドが
52 \fIexit(127)\fP を実行した場合と同じになる。
53 .PP
54 \fIcommand\fP の値が NULL のときは、 \fBsystem\fP()  はシェルが利用可能ならゼロ以外の値を返し、利用不可ならゼロを返す。
55 .PP
56 \fBsystem\fP()  は他の子プロセスのウエイトステータスには影響を与えない。
57 .SH 準拠
58 C89, C99, POSIX.1\-2001.
59 .SH 注意
60 .PP
61 (「どの」ヘッダファイルをインクルードするよりも前に)  機能検査マクロ \fB_XOPEN_SOURCE\fP が定義された場合には、 \fBwait\fP(2)
62 で説明されているマクロ群 (\fBWEXITSTATUS\fP()  等) が \fI<stdlib.h>\fP
63 をインクルードすると利用可能になる。
64 .PP
65 既に述べたように、 \fBsystem\fP()  は \fBSIGINT\fP と \fBSIGQUIT\fP を無視する。 よってループから \fBsystem\fP()
66 を呼ぶプログラムは、 以下の例のように子プロセスの終了状態を自分でチェックしておかないと、 中断できなくなるかもしれない。
67 .br
68 .nf
69
70     while (something) {
71         int ret = system("foo");
72
73         if (WIFSIGNALED(ret) &&
74             (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
75                 break;
76     }
77 .fi
78 .PP
79 set\-user\-ID や set\-group\-ID の特権をもつプログラムの中では \fBsystem\fP()
80 を使ってはいけない。なぜなら、ある環境変数の未知の値によって システムの安全が損なわれるからである。代わりに \fBexec\fP(3)  関連の関数群の中で
81 \fBexeclp\fP(3)  と \fBexecvp\fP(3)  以外の関数を使用すべきである。 実際のところ、 \fBsystem\fP()  は
82 \fI/bin/sh\fP が bash バージョン 2 であるシステムでは、 set\-user\-ID や set\-group\-ID
83 の特権を持つプログラムからは正しく動作しない。 なぜなら、bash バージョン 2 はスタートアップ時に特権を落とすからである。 (Debian
84 では、sh として起動された時にはこのような動作を行なわないように 修正された bash を用いている)
85 .PP
86 glibc 2.1.3 より前のバージョンでは、 \fIcommand\fP が NULL の場合に \fI/bin/sh\fP
87 が利用可能かどうかのチェックは実際には行わず、 いつでも利用可能であるとみなしていた。 \fBsystem\fP()  はこの場合に常に 1 を返していた。
88 POSIX.1\-2001 ではシェルが提供されているという標準に準拠した実装を 要求しているが、glibc 2.1.3
89 以降ではシェルのチェックを実行している。 なぜなら、呼び出し元のプログラムが \fBsystem\fP()  を呼び出すより前に (POSIX.1\-2001
90 では規定されていない)  \fBchroot\fP(2)  を呼び出していた時には、シェルが利用可能でない場合や実行可能ファイル でない場合があるからである。
91 .PP
92 実行したシェルコマンドが 127 (\fB/bin/sh\fP の呼び出しに失敗した時に返す値) を返すことも考えられる。 そのため、プログラムは
93 (リターンコードを見るだけでは)  \fBexecve\fP(2)  の呼び出しが失敗したことを確実に知ることはできない。
94 .SH 関連項目
95 \fBsh\fP(1), \fBsignal\fP(2), \fBwait\fP(2), \fBexec\fP(3)
96 .SH この文書について
97 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
98 である。プロジェクトの説明とバグ報告に関する情報は
99 http://www.kernel.org/doc/man\-pages/ に書かれている。