Provided by: manpages-ja-dev_0.5.0.0.20221215+dfsg-1_all bug

名前

       execl, execlp, execle, execv, execvp, execvpe - ファイルを実行する

書式

       #include <unistd.h>

       extern char **environ;

       int execl(const char *pathname, const char *arg, ...
       /* (char  *) NULL */);
       int execlp(const char *file, const char *arg, ...
       /* (char  *) NULL */);
       int execle(const char *pathname, const char *arg, ...
                       /*, (char *) NULL, char *const envp[] */);
       int execv(const char *pathname, char *const argv[]);
       int execvp(const char *file, char *const argv[]);
       int execvpe(const char *file, char *const argv[],
                       char *const envp[]);

   glibc 向けの機能検査マクロの要件 (feature_test_macros(7)  参照):

       execvpe(): _GNU_SOURCE

説明

       The  exec()   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  execve(2).   (See  the  manual  page  for
       execve(2)  for further details about the replacement of the current process image.)

       これらの関数の最初の引数は、実行されるファイルの名前である。

       The functions can be grouped based on the letters following the "exec" prefix.

   l - execl(), execlp(), execle()
       const  char *arg とそれに続く省略部分は arg0, arg1, ..., argn とみなされる。 これらには、実行されるプログ
       ラムで利用可能な引数のリストを指定する  (引数のリストは  ヌルで終端された文字列へのポインターから構成され
       る)。 慣習として、最初の引数は、実行されるファイル名 へのポインターにする。引数のリストは必ず NULL で終わ
       らなければならず、これらの関数は可変長引数関数なので、 このポインターは (char *) NULL  とキャストしなけれ
       ばならない。

       By  contrast  with the 'l' functions, the 'v' functions (below) specify the command-line arguments of the
       executed program as a vector.

    v - execv(), execvp(), execvpe()
       The char *const argv[] 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 must be  terminated  by  a  null
       pointer.

    e - execle(), execvpe()
       The  environment  of  the  caller  is  specified via the argument envp.  The envp argument is an array of
       pointers to null-terminated strings and must be terminated by a null pointer.

       All other exec()  functions (which do not include 'e' in the suffix) take the  environment  for  the  new
       process image from the external variable environ in the calling process.

   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 PATH environment variable.  If this variable isn't defined, the path
       list defaults to a list that includes the directories  returned  by  confstr(_CS_PATH)  (which  typically
       returns  the  value  "/bin:/usr/bin")   and  possibly  also  the current working directory; see NOTES for
       further details.

       指定されたファイル名がスラッシュを含む場合、 PATH は無視され、指定されたパス名のファイルが実行される。

       さらに、いくつかのエラーは特別に処理される。

       ファイルが実行ファイルでない場合 (このとき呼び出そうとした execve(2)  はエラー EACCES で失敗する)、これら
       の関数は残りの検索パスの検索を続ける。  他にファイルが見つからなくなった場合 errnoEACCES を設定し復帰
       する。

       ファイルのヘッダーが実行形式として認識できない場合 (このとき呼び出そうとした execve(2)  はエラー  ENOEXEC
       で失敗する)、これらの関数はそのファイルを最初の引数としたシェル (/bin/sh)  を実行する (これにも失敗した場
       合、これ以上の検索は行われない)。

       All other exec()  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.

返り値

       exec()   群の関数が復帰するのは、エラーが発生した場合のみである。 返り値は -1 で、 errno にエラーの内容が
       セットされる。

エラー

       これら全ての関数は失敗する場合がある。その場合、 execve(2)  に対して規定されたエラーが  errno  に設定され
       る。

バージョン

       execvpe()  関数は glibc 2.11 で初めて登場した。

属性

       この節で使用されている用語の説明については、 attributes(7) を参照。

       ┌──────────────────────────────┬───────────────┬─────────────┐
       │インターフェース属性          │
       ├──────────────────────────────┼───────────────┼─────────────┤
       │execl(), execle(), execv()    │ Thread safety │ MT-Safe     │
       ├──────────────────────────────┼───────────────┼─────────────┤
       │execlp(), execvp(), execvpe() │ Thread safety │ MT-Safe env │
       └──────────────────────────────┴───────────────┴─────────────┘

準拠

       POSIX.1-2001, POSIX.1-2008.

       execvpe()  関数は GNU による拡張である。

注意

       The  default  search  path  (used  when  the  environment does not contain the variable PATH)  shows some
       variation across systems.  It generally includes /bin and /usr/bin (in that order) and may  also  include
       the  current  working  directory.   On some other systems, the current working is included after /bin and
       /usr/bin, 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.

       ファイルを実行しようとしている間にエラーが発生した時の execlp()  と execvp() のふるまいについて歴史的な慣
       習はあるが、伝統的に文書として記載されておらず、  POSIX 標準でも規定されていない。BSD (またおそらく他のシ
       ステム) では、 ETXTBSY が発生した場合、自動的に中断 (sleep) し再試行を行う。 Linux はそれをハードエラーと
       して取り扱い即座に復帰する。

       伝統的に、関数  execlp()   と  execvp()   は、上で説明したエラーと、これら 2 つの関数自身が返す ENOMEME2BIG 以外の全てのエラーを無視していたが、 今では、上で説明した以外のエラーが発生した場合でも、  返ってく
       るよう変更された。

バグ

       Before  glibc  2.24,  execl()   and  execle()   employed  realloc(3) internally and were consequently not
       async-signal-safe, in violation of the requirements of POSIX.1.  This was fixed in glibc 2.24.

   アーキテクチャー固有の詳細
       On sparc and sparc64, execv()  is provided as a system call by  the  kernel  (with  the  prototype  shown
       above)   for compatibility with SunOS.  This function is not employed by the execv()  wrapper function on
       those architectures.

関連項目

        sh(1), execve(2), execveat(2), fork(2), ptrace(2), fexecve(3), system(3), environ(7)

この文書について

       この man ページは Linux man-pages プロジェクトのリリース 5.10  の一部である。プロジェクトの説明とバグ報告
       に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。