Man page - exec(3)

Packages contains this manual

Available languages:

en fr pl ja zh_TW zh_CN de

Manual

EXEC

名 前
書 式
説 明
l - execl(), execlp(), execle()
v - execv(), execvp(), execvpe()
e - execle(), execvpe()
p - execlp(), execvp(), execvpe()
返 り 値
エ ラ ー
バ ー ジ ョ ン
属 性
準 拠
注 意
バ グ
ア ー キ テ ク チ ャ ー 固 有 の 詳 細
関 連 項 目
こ の 文 書 に つ い て

名 前

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 で 失 敗 す る )、 こ れ ら の 関 数 は 残 り の 検 索 パ ス の 検 索 を 続 け る 。 他 に フ ァ イ ル が 見 つ か ら な く な っ た 場 合 errno EACCES を 設 定 し 復 帰 す る 。

フ ァ イ ル の ヘ ッ ダ ー が 実 行 形 式 と し て 認 識 で き な い 場 合 (こ の と き 呼 び 出 そ う と し た 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) を 参 照 。

Image grohtml-28244-1.png

準 拠

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 つ の 関 数 自 身 が 返 す ENOMEM E2BIG 以 外 の 全 て の エ ラ ー を 無 視 し て い た が 、 今 で は 、 上 で 説 明 し た 以 外 の エ ラ ー が 発 生 し た 場 合 で も 、 返 っ て く る よ う 変 更 さ れ た 。

バ グ

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/ に 書 か れ て い る 。