.\" Copyright (c) 1991 The Regents of the University of California. .\" All rights reserved. .\" .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB) .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" %%%LICENSE_END .\" .\" @(#)exec.3 6.4 (Berkeley) 4/19/91 .\" .\" Converted for Linux, Mon Nov 29 11:12:48 1993, faith@cs.unc.edu .\" Updated more for Linux, Tue Jul 15 11:54:18 1997, pacman@cqc.com .\" Modified, 24 Jun 2004, Michael Kerrisk .\" Added note on casting NULL .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1998 Masato Taruishi .\" all rights reserved. .\" Translated 1998-05-27, Masato Taruishi .\" Modified 1998-08-08, Fujiwara Teruyoshi .\" Modified 2000-10-06, Kentaro Shirakata .\" Modified 2005-02-26, Akihiro MOTOKI .\" Updated 2010-10-27, Akihiro Motoki , LDP v3.29 .\" .TH EXEC 3 2019\-08\-02 GNU "Linux Programmer's Manual" .SH 名前 execl, execlp, execle, execv, execvp, execvpe \- ファイルを実行する .SH 書式 .nf \fB#include \fP .PP \fBextern char **environ;\fP .PP \fBint execl(const char *\fP\fIpathname\fP\fB, const char *\fP\fIarg\fP\fB, ...\fP \fB/* (char *) NULL */);\fP \fBint execlp(const char *\fP\fIfile\fP\fB, const char *\fP\fIarg\fP\fB, ...\fP \fB/* (char *) NULL */);\fP \fBint execle(const char *\fP\fIpathname\fP\fB, const char *\fP\fIarg\fP\fB, ...\fP \fB /*, (char *) NULL, char *const \fP\fIenvp\fP\fB[] */);\fP \fBint execv(const char *\fP\fIpathname\fP\fB, char *const \fP\fIargv\fP\fB[]);\fP \fBint execvp(const char *\fP\fIfile\fP\fB, char *const \fP\fIargv\fP\fB[]);\fP \fBint execvpe(const char *\fP\fIfile\fP\fB, char *const \fP\fIargv\fP\fB[],\fP \fB char *const \fP\fIenvp\fP\fB[]);\fP .fi .PP .RS -4 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .RE .PP \fBexecvpe\fP(): _GNU_SOURCE .SH 説明 The \fBexec\fP() family of functions replaces the current process image with a new process image. The functions described in this manual page are layered on top of \fBexecve\fP(2). (See the manual page for \fBexecve\fP(2) for further details about the replacement of the current process image.) .PP これらの関数の最初の引数は、実行されるファイルの名前である。 .PP .\" The functions can be grouped based on the letters following the "exec" prefix. .SS "l \- execl(), execlp(), execle()" \fIconst char\ *arg\fP とそれに続く省略部分は \fIarg0\fP, \fIarg1\fP, \&..., \fIargn\fP とみなされる。 これらには、実行されるプログラムで利用可能な引数のリストを指定する (引数のリストは ヌルで終端された文字列へのポインターから構成される)。 慣習として、最初の引数は、実行されるファイル名 へのポインターにする。引数のリストは必ず NULL で終わらなければならず、これらの関数は可変長引数関数なので、 このポインターは \fI(char\ *) NULL\fP とキャストしなければならない。 .PP .\" By contrast with the 'l' functions, the 'v' functions (below) specify the command\-line arguments of the executed program as a vector. .SS " v \- execv(), execvp(), execvpe()" The \fIchar\ *const argv[]\fP argument is an array of pointers to null\-terminated strings that represent the argument list available to the new program. The first argument, by convention, should point to the filename associated with the file being executed. The array of pointers \fImust\fP be terminated by a null pointer. .SS " e \- execle(), execvpe()" The environment of the caller is specified via the argument \fIenvp\fP. The \fIenvp\fP argument is an array of pointers to null\-terminated strings and \fImust\fP be terminated by a null pointer. .PP All other \fBexec\fP() functions (which do not include 'e' in the suffix) take the environment for the new process image from the external variable \fIenviron\fP in the calling process. .SS "p \- execlp(), execvp(), execvpe()" These functions duplicate the actions of the shell in searching for an executable file if the specified filename does not contain a slash (/) character. The file is sought in the colon\-separated list of directory pathnames specified in the \fBPATH\fP environment variable. If this variable isn't defined, the path list defaults to a list that includes the directories returned by \fIconfstr(_CS_PATH)\fP (which typically returns the value "/bin:/usr/bin") and possibly also the current working directory; see NOTES for further details. .PP 指定されたファイル名がスラッシュを含む場合、 \fBPATH\fP は無視され、指定されたパス名のファイルが実行される。 .PP さらに、いくつかのエラーは特別に処理される。 .PP ファイルが実行ファイルでない場合 (このとき呼び出そうとした \fBexecve\fP(2) はエラー \fBEACCES\fP で失敗する)、これらの関数は残りの検索パスの検索を続ける。 他にファイルが見つからなくなった場合 \fIerrno\fP に \fBEACCES\fP を設定し復帰する。 .PP ファイルのヘッダーが実行形式として認識できない場合 (このとき呼び出そうとした \fBexecve\fP(2) はエラー \fBENOEXEC\fP で失敗する)、これらの関数はそのファイルを最初の引数としたシェル (\fI/bin/sh\fP) を実行する (これにも失敗した場合、これ以上の検索は行われない)。 .PP All other \fBexec\fP() functions (which do not include 'p' in the suffix) take as their first argument a (relative or absolute) pathname that identifies the program to be executed. .SH 返り値 \fBexec\fP() 群の関数が復帰するのは、エラーが発生した場合のみである。 返り値は \-1 で、 \fIerrno\fP にエラーの内容がセットされる。 .SH エラー これら全ての関数は失敗する場合がある。その場合、 \fBexecve\fP(2) に対して規定されたエラーが \fIerrno\fP に設定される。 .SH バージョン \fBexecvpe\fP() 関数は glibc 2.11 で初めて登場した。 .SH 属性 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。 .TS allbox; lbw29 lb lb l l l. インターフェース 属性 値 T{ \fBexecl\fP(), \fBexecle\fP(), \fBexecv\fP() T} Thread safety MT\-Safe T{ \fBexeclp\fP(), \fBexecvp\fP(), \fBexecvpe\fP() T} Thread safety MT\-Safe env .TE .SH 準拠 POSIX.1\-2001, POSIX.1\-2008. .PP \fBexecvpe\fP() 関数は GNU による拡張である。 .SH 注意 .\" glibc commit 1eb8930608705702d5746e5491bab4e4429fcb83 The default search path (used when the environment does not contain the variable \fBPATH\fP) shows some variation across systems. It generally includes \fI/bin\fP and \fI/usr/bin\fP (in that order) and may also include the current working directory. On some other systems, the current working is included after \fI/bin\fP and \fI/usr/bin\fP, as an anti\-Trojan\-horse measure. The glibc implementation long followed the traditional default where the current working directory is included at the start of the search path. However, some code refactoring during the development of glibc 2.24 caused the current working directory to be dropped altogether from the default search path. This accidental behavior change is considered mildly beneficial, and won't be reverted. .PP ファイルを実行しようとしている間にエラーが発生した時の \fBexeclp\fP() と \fBexecvp\fP() のふるまいについて歴史的な慣習はあるが、伝統的に文書として記載されておらず、 POSIX 標準でも規定されていない。BSD (またおそらく他のシステム) では、 \fBETXTBSY\fP が発生した場合、自動的に中断 (sleep) し再試行を行う。 Linux はそれをハードエラーとして取り扱い即座に復帰する。 .PP 伝統的に、関数 \fBexeclp\fP() と \fBexecvp\fP() は、上で説明したエラーと、これら 2 つの関数自身が返す \fBENOMEM\fP と \fBE2BIG\fP 以外の全てのエラーを無視していたが、 今では、上で説明した以外のエラーが発生した場合でも、 返ってくるよう変更された。 .SH バグ .\" https://sourceware.org/bugzilla/show_bug.cgi?id=19534 .\" Before glibc 2.24, \fBexecl\fP() and \fBexecle\fP() employed \fBrealloc\fP(3) internally and were consequently not async\-signal\-safe, in violation of the requirements of POSIX.1. This was fixed in glibc 2.24. .SS アーキテクチャー固有の詳細 On sparc and sparc64, \fBexecv\fP() is provided as a system call by the kernel (with the prototype shown above) for compatibility with SunOS. This function is \fInot\fP employed by the \fBexecv\fP() wrapper function on those architectures. .SH 関連項目 \fBsh\fP(1), \fBexecve\fP(2), \fBexecveat\fP(2), \fBfork\fP(2), \fBptrace\fP(2), \fBfexecve\fP(3), \fBsystem\fP(3), \fBenviron\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。