Section (2) execveat
execveat — execute program relative to a directory file descriptor
|const char *pathname,|
|char *const argv,|
|char *const envp,|
execveat() system call
executes the program referred to by the combination of
pathname. It operates in
exactly the same way as execve(2), except for the
differences described in this manual page.
If the pathname given in
pathname is relative, then it
is interpreted relative to the directory referred to by the
(rather than relative to the current working directory of the
calling process, as is done by execve(2) for a relative
the special value
interpreted relative to the current working directory of the
calling process (like execve(2)).
pathname is an
empty string and the
AT_EMPTY_PATH flag is specified, then the
specifies the file to be executed (i.e.,
dirfd refers to an executable
file, rather than a directory).
is a bit mask that can include zero or more of the following
pathnameis an empty string, operate on the file referred to by
dirfd(which may have been obtained using the open(2)
If the file identified by
dirfdand a non-NULL
pathnameis a symbolic link, then the call fails with the error ELOOP.
not return. On error, −1 is returned, and
errno is set appropriately.
The same errors that occur for execve(2) can also occur
execveat(). The following
additional errors can occur for
dirfdis not a valid file descriptor.
Invalid flag specified in
AT_SYMLINK_NOFOLLOWand the file identified by
dirfdand a non-NULL
pathnameis a symbolic link.
The program identified by
pathnamerequires the use of an interpreter program (such as a script starting with #!), but the file descriptor
dirfdwas opened with the
O_CLOEXECflag, with the result that the program file is inaccessible to the launched interpreter. See BUGS.
pathnameis relative and
dirfdis a file descriptor referring to a file other than a directory.
When asked to execute a script file, the
argv that is passed to the
script interpreter is a string of the form
N is the number of the file descriptor
passed via the
argument. A string of the first form occurs when
AT_EMPTY_PATH is employed. A string of the
second form occurs when the script is specified via both
pathname; in this case,
P is the value given in
For the same reasons described in fexecve(3), the natural
idiom when using
to set the close-on-exec flag on
dirfd. (But see BUGS.)
The ENOENT error described above means that it is not possible to set the close-on-exec flag on the file descriptor given to a call of the form:
execveat(fd, , argv, envp, AT_EMPTY_PATH);
However, the inability to set the close-on-exec flag means
that a file descriptor referring to the script leaks through
to the script itself. As well as wasting a file descriptor,
this leakage can lead to file-descriptor exhaustion in
scenarios where scripts recursively employ
This page is part of release 4.16 of the Linux
man-pages project. A
description of the project, information about reporting bugs,
and the latest version of this page, can be found at
Copyright (c) 2014 Google, Inc., written by David Drysdale
and Copyright (c) 2015, Michael Kerrisk <mtk.manpagesgmail.com>
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Since the Linux kernel and libraries are constantly changing, this
manual page may be incorrect or out-of-date. The author(s) assume no
responsibility for errors or omissions, or for damages resulting from
the use of the information contained herein. The author(s) may not
have taken the same level of care in the production of this manual,
which is licensed free of charge, as they might when working
Formatted or processed versions of this manual, if unaccompanied by
the source, must acknowledge the copyright and authors of this work.