OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / draft / man3 / exec.3
1 .\" Copyright (c) 1991 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)exec.3      6.4 (Berkeley) 4/19/91
33 .\"
34 .\" Converted for Linux, Mon Nov 29 11:12:48 1993, faith@cs.unc.edu
35 .\" Updated more for Linux, Tue Jul 15 11:54:18 1997, pacman@cqc.com
36 .\" Modified, 24 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
37 .\"     Added note on casting NULL
38 .\"
39 .\" Japanese Version Copyright (c) 1998 Masato Taruishi
40 .\"         all rights reserved.
41 .\" Translated 1998-05-27, Masato Taruishi
42 .\" Modified 1998-08-08, Fujiwara Teruyoshi <fujiwara@linux.or.jp>
43 .\" Modified 2000-10-06, Kentaro Shirakata <argrath@ub32.org>
44 .\" Modified 2005-02-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
45 .\" Updated 2010-10-27, Akihiro Motoki <amotoki@dd.iij4u.or.jp>, LDP v3.29
46 .\"
47 .\"WORD:        null-terminated strings    NULLで終わる文字列
48 .\"WORD:        anti-Trojan-horse measure  トロイの木馬対策
49 .\"WORD:        external variable          外部変数
50 .\"WORD:        current  directory first   カレントディレクトリが最初
51 .\"WORD:        the attempted execve       呼び出そうとしたexecve
52 .\"WORD:        variadic function          可変長引き数関数
53 .\"WORD:        semantics                  (プログラムの)動作
54 .\"
55 .TH EXEC 3  2010-09-25 "GNU" "Linux Programmer's Manual"
56 .\"O .SH NAME
57 .SH 名前
58 .\"O execl, execlp, execle, execv, execvp, execvpe \- execute a file
59 execl, execlp, execle, execv, execvp, execvpe \- ファイルを実行する
60 .\"O .SH SYNOPSIS
61 .SH 書式
62 .B #include <unistd.h>
63 .sp
64 .B extern char **environ;
65 .sp
66 .BI "int execl(const char *" path ", const char *" arg ", ...);"
67 .br
68 .BI "int execlp(const char *" file ", const char *" arg ", ...);"
69 .br
70 .BI "int execle(const char *" path ", const char *" arg ,
71 .br
72 .BI "           ..., char * const " envp "[]);"
73 .br
74 .BI "int execv(const char *" path ", char *const " argv "[]);"
75 .br
76 .BI "int execvp(const char *" file ", char *const " argv "[]);"
77 .br
78 .BI "int execvpe(const char *" file ", char *const " argv "[],"
79 .br
80 .BI "           char *const " envp "[]);"
81 .sp
82 .in -4n
83 .\"O Feature Test Macro Requirements for glibc (see
84 .\"O .BR feature_test_macros (7)):
85 glibc 向けの機能検査マクロの要件
86 .RB ( feature_test_macros (7)
87 参照):
88 .in
89 .sp
90 .BR execvpe ():
91 _GNU_SOURCE
92 .\"O .SH DESCRIPTION
93 .SH 説明
94 .\"O The
95 .\"O .BR exec ()
96 .\"O family of functions replaces the current process image with a new process
97 .\"O image.
98 .\"O The functions described in this manual page are front-ends for
99 .\"O .BR execve (2).
100 .\"O (See the manual page for
101 .\"O .BR execve (2)
102 .\"O for further details about the replacement of the current process image.)
103 .BR exec ()
104 ファミリーの関数は現在のプロセスイメージを新しいプロセスイメージで置き
105 換える。このマニュアルで説明されている関数は
106 .BR execve (2)
107 のフロントエンドである。
108 (現在のプロセスイメージの置き換えについての詳細は
109 .BR execve (2)
110 のマニュアルを参照)
111 .PP
112 .\"O The initial argument for these functions is the name of a file that is
113 .\"O to be executed.
114 これらの関数の最初の引き数は、実行されるファイルの名前である。
115 .PP
116 .\"O The
117 .\"O .I "const char *arg"
118 .\"O and subsequent ellipses in the
119 .\"O .BR execl (),
120 .\"O .BR execlp (),
121 .\"O and
122 .\"O .BR execle ()
123 .\"O functions can be thought of as
124 .\"O .IR arg0 ,
125 .\"O .IR arg1 ,
126 .\"O \&...,
127 .\"O .IR argn .
128 関数
129 .BR execl (),
130 .BR execlp (),
131 .BR execle ()
132
133 .I "const char *arg"
134 とそれに続く省略部分は
135 .IR arg0 ,
136 .IR arg1 ,
137 \&...,
138 .I argn
139 とみなされる。
140 .\"O Together they describe a list of one or more pointers to null-terminated
141 .\"O strings that represent the argument list available to the executed program.
142 .\"O The first argument, by convention, should point to the filename associated
143 .\"O with the file being executed.
144 .\"O The list of arguments
145 .\"O .I must
146 .\"O be terminated by a NULL
147 .\"O pointer, and, since these are variadic functions, this pointer must be cast
148 .\"O .IR "(char *) NULL" .
149 これらには、実行されるプログラムで利用可能な引き数のリストを指定する
150 (引き数のリストは NULL で終端された文字列へのポインタから構成される)。
151 慣習として、最初の引き数は、実行されるファイル名
152 へのポインタにする。引き数のリストは必ず NULL
153 で終わらなければならず、これらの関数は可変長引き数関数なので、
154 このポインタは
155 .I "(char *) NULL"
156 とキャストしなければならない。
157 .PP
158 .\"O The
159 .\"O .BR execv (),
160 .\"O .BR execvp (),
161 .\"O and
162 .\"O .BR execvpe ()
163 .\"O functions provide an array of pointers to null-terminated strings that
164 .\"O represent the argument list available to the new program.
165 .\"O The first argument, by convention, should point to the filename
166 .\"O associated with the file being executed.
167 .\"O The array of pointers
168 .\"O .I must
169 .\"O be terminated by a NULL pointer.
170 関数
171 .BR execv (),
172 .BR execvp (),
173 .BR execvpe ()
174 は、利用可能な引き数リスト (NULL で終端された文字列への
175 ポインタの配列) を新しいプログラムに渡す。
176 慣習として、最初の引き数は実行されるファイル名へ
177 のポインタにする。ポインタの配列は必ず
178 NULL で終わらなければならない。
179 .PP
180 .\"O The
181 .\"O .BR execle ()
182 .\"O and
183 .\"O .BR execvpe ()
184 .\"O functions allow the caller to specify the environment of the
185 .\"O executed program via the argument
186 .\"O .IR envp .
187 関数
188 .BR execle (),
189 .BR execvpe ()
190 では、呼び出し元が引き数
191 .I envp
192 経由実行されるプログラムの環境を指定することができる。
193 .\"O The
194 .\"O .I envp
195 .\"O argument is an array of pointers to null-terminated strings and
196 .\"O .I must
197 .\"O be terminated by a NULL pointer.
198 .\"O The other functions take the environment for the new process
199 .\"O image from the external variable
200 .\"O .I environ
201 .\"O in the calling process.
202 .I envp
203 引き数は、NULL で終端された文字列へのポインタの配列であり、
204 NULL ポインタで終わらなければならない。
205 他の関数では、呼び出し元のプロセスの外部変数
206 .B environ
207 から新しいプロセス用の環境を与える。
208 .\"O .SS Special semantics for execlp() and execvp()
209 .SS execlp() と execvp() の特別な動作
210 .PP
211 .\"O The
212 .\"O .BR execlp (),
213 .\"O .BR execvp (),
214 .\"O and
215 .\"O .BR execvpe ()
216 .\"O functions duplicate the actions of the shell in
217 .\"O searching for an executable file
218 .\"O if the specified filename does not contain a slash (/) character.
219 関数
220 .BR execlp (),
221 .BR execvp (),
222 .BR execvpe ()
223 は、指定されたファイル名がスラッシュ (/) を含んでいない場合、
224 シェルと同じ動作で実行可能なファイルを探索する。
225 .\"O The file is sought in the colon-separated list of directory pathnames
226 .\"O specified in the
227 .\"O .B PATH
228 .\"O environment variable.
229 .\"O If this variable isn't defined, the path list defaults to
230 .\"O the current directory followed by the list of directories returned by
231 .\"O .IR confstr(_CS_PATH) .
232 .\"O (This
233 .\"O .BR confstr (3)
234 .\"O call typically returns the value "/bin:/usr/bin".)
235 ファイルの検索は、環境変数
236 .B PATH
237 で指定されたコロン区切りのディレクトリのパス名のリストを対象に行われる。
238 この変数が定義されていない場合、パス名のリストのデフォルト値として、
239 カレントディレクトリの後ろに、
240 .I confstr(_CS_PATH)
241 が返すディレクトリのリストをつなげた値が使用される (この
242 .BR confstr (3)
243 の呼び出しでは通常 "/bin:/usr/bin" が返される)。
244
245 .\"O If the specified filename includes a slash character, then
246 .\"O .B PATH
247 .\"O is ignored, and the file at the specified pathname is executed.
248 指定されたファイル名がスラッシュを含む場合、
249 .B PATH
250 は無視され、指定されたパス名のファイルが実行される。
251
252 .\"O In addition, certain errors are treated specially.
253 さらに、いくつかのエラーは特別に処理される。
254
255 .\"O If permission is denied for a file (the attempted
256 .\"O .BR execve (2)
257 .\"O failed with the error
258 .\"O .BR EACCES ),
259 .\"O these functions will continue searching the rest of the search path.
260 .\"O If no other file is found, however,
261 .\"O they will return with
262 .\"O .I errno
263 .\"O set to
264 .\"O .BR EACCES .
265 ファイルが実行ファイルでない場合 (このとき呼び出そうとした
266 .BR execve (2)
267 はエラー
268 .B EACCES
269 で失敗する)、これらの関数は残りの検索パスの検索を続ける。
270 他にファイルが見つからなくなった場合
271 .I errno
272
273 .B EACCES
274 を設定し復帰する。
275 .\" fujiwara: 個人的には「復帰する」の方が好き(^_^;
276
277 .\"O If the header of a file isn't recognized (the attempted
278 .\"O .BR execve (2)
279 .\"O failed with the error
280 .\"O .BR ENOEXEC ),
281 .\"O these functions will execute the shell
282 .\"O .RI ( /bin/sh )
283 .\"O with the path of the file as its first argument.
284 .\"O (If this attempt fails, no further searching is done.)
285 ファイルのヘッダが実行形式として認識できない場合
286 (このとき呼び出そうとした
287 .BR execve (2)
288 はエラー
289 .B ENOEXEC
290 で失敗する)、これらの関数はそのファイルを最初の引き数としたシェル
291 .RI ( /bin/sh )
292 を実行する (これにも失敗した場合、これ以上の検索は行われない)。
293 .\"O .SH "RETURN VALUE"
294 .SH 返り値
295 .\"O The
296 .\"O .BR exec ()
297 .\"O functions only return if an error has have occurred.
298 .\"O The return value is \-1, and
299 .\"O .I errno
300 .\"O is set to indicate the error.
301 .BR exec ()
302 群の関数が復帰するのは、エラーが発生した場合のみである。
303 返り値は \-1 で、
304 .I errno
305 にエラーの内容がセットされる。
306 .\"O .SH ERRORS
307 .SH エラー
308 .\"O All of these functions may fail and set
309 .\"O .I errno
310 .\"O for any of the errors specified for
311 .\"O .BR execve (2).
312 これら全ての関数は失敗する場合がある。その場合、
313 .BR execve (2)
314 に対して規定されたエラーが
315 .I errno
316 に設定される。
317 .\"O .SH VERSIONS
318 .SH バージョン
319 .\"O The
320 .\"O .BR execvpe ()
321 .\"O function first appeared in glibc 2.11.
322 .BR execvpe ()
323 関数は glibc 2.11 で初めて登場した。
324 .\"O .SH "CONFORMING TO"
325 .SH 準拠
326 POSIX.1-2001, POSIX.1-2008.
327
328 .\"O The
329 .\"O .BR execvpe ()
330 .\"O function is a GNU extension.
331 .BR execvpe ()
332 関数は GNU による拡張である。
333 .\"O .SH NOTES
334 .SH 注意
335 .\"O On some other systems, the default path (used when the environment
336 .\"O does not contain the variable \fBPATH\fR) has the current working
337 .\"O directory listed after
338 .\"O .I /bin
339 .\"O and
340 .\"O .IR /usr/bin ,
341 .\"O as an anti-Trojan-horse measure.
342 .\"O Linux uses here the
343 .\"O traditional "current directory first" default path.
344 Linux 以外のシステムには、
345 (環境変数 \fBPATH\fR が定義されていないときの)
346 デフォルトのパスにおいて、カレント・ディレクトリが
347 .I /bin
348
349 .I /usr/bin
350 の後ろに配置されるものもある。
351 これはトロイの木馬対策のためである。
352 Linux では、デフォルトのパスに、昔ながらの「現在のディレクトリを
353 先に探索」というルールを使っている。
354 .PP
355 .\"O The behavior of
356 .\"O .BR execlp ()
357 .\"O and
358 .\"O .BR execvp ()
359 .\"O when errors occur while attempting to execute the file is historic
360 .\"O practice, but has not traditionally been documented and is not specified by
361 .\"O the POSIX standard.
362 .\"O BSD (and possibly other systems) do an automatic
363 .\"O sleep and retry if
364 .\"O .B ETXTBSY
365 .\"O is encountered.
366 .\"O Linux treats it as a hard
367 .\"O error and returns immediately.
368 ファイルを実行しようとしている間にエラーが発生した時の
369 .BR execlp ()
370
371 .BR execvp ()
372 のふるまいについて歴史的な慣習はあるが、伝統的に文書として記載されておらず、
373 POSIX 標準でも規定されていない。BSD (またおそらく他のシステム) では、
374 .B ETXTBSY
375 が発生した場合、自動的に中断 (sleep) し再試行を行う。
376 Linux はそれをハードエラーとして取り扱い即座に復帰する。
377 .PP
378 .\"O Traditionally, the functions
379 .\"O .BR execlp ()
380 .\"O and
381 .\"O .BR execvp ()
382 .\"O ignored all errors except for the ones described above and
383 .\"O .B ENOMEM
384 .\"O and
385 .\"O .BR E2BIG ,
386 .\"O upon which they returned.
387 .\"O They now return if any error other than the ones
388 .\"O described above occurs.
389 伝統的に、関数
390 .BR execlp ()
391
392 .BR execvp ()
393 は、上で説明したエラーと、これら 2 つの関数自身が返す
394 .B ENOMEM
395
396 .B E2BIG
397 以外の全てのエラーを無視していたが、
398 今では、上で説明した以外のエラーが発生した場合でも、
399 返ってくるよう変更された。
400 .\"O .SH "SEE ALSO"
401 .SH 関連項目
402 .BR sh (1),
403 .BR execve (2),
404 .BR fork (2),
405 .BR ptrace (2),
406 .BR fexecve (3),
407 .BR environ (7)