Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

exec family: execl, execlp, execle, execv, execvp, execvpe, execve, fexecve - glibc

Split from the chapter glibc: Process, Threads and Signals into the per-function layout; see the method page and the glibc ledger for coverage status.

FieldValue
IDGLIBC-execl, GLIBC-execlp, GLIBC-execle, GLIBC-execv, GLIBC-execve, GLIBC-execvp, GLIBC-fexecve; GLIBC-execvpe (triage row)
Headerunistd.h; execvpe needs _GNU_SOURCE, fexecve needs _POSIX_C_SOURCE >= 200809L
Provenancel/v core: POSIX.1; execvpe: GNU (glibc 2.11); fexecve: POSIX.1-2008
Wrapsexecve(2); fexecve uses execveat(2) (directly since glibc 2.34)
Statusdocumented

Semantics – replace the current process image. Suffixes: l = varargs list terminated by (char *) NULL (the cast is mandatory for variadic calls); v = argv[] vector; e = explicit envp[], all others take the environment from the global environ; p = PATH search when the name contains no slash.

PATH search (the p functions) – search $PATH; if unset, use the confstr(_CS_PATH) default (typically /bin:/usr/bin). glibc <= 2.23 silently put the current working directory at the front of that default; a 2.24 refactoring dropped CWD entirely (kept as intentional). Two errors are special: EACCES on one candidate continues the search (final EACCES only if nothing else matches), and ENOEXEC makes glibc run /bin/sh with the file as its first argument. execvpe searches the PATH of the caller’s environment, not of the envp argument. BSD sleeps and retries on ETXTBSY; Linux returns it immediately.

glibc layer – these are pure library functions over execve(2); before glibc 2.24 execl/execle were not async-signal-safe (internal realloc), fixed in 2.24. fexecve takes a file descriptor (opened O_RDONLY or O_PATH) and fails with ENOSYS where neither /proc nor execveat support exists; since 2.34 it issues execveat directly instead of a /proc/self/fd fallback.

Return and errors – only ever return on failure: -1 with the execve(2) error set (E2BIG, ENOEXEC, ENOMEM, EACCES, ENOENT, …). Streams never survive exec; ignored dispositions are inherited, all others reset to default; FD_CLOEXEC descriptors close.

References – exec(3), execve(2); syscall view: execve.