Section: Linux Programmer's Manual (2)
Return to Main Contents
execveat - execute program relative to a directory file descriptor
int execveat(int dirfd, const char *pathname,
char *const argv, char *const envp,
system call executes the program referred to by the combination of
It operates in exactly the same way as
except for the differences described in this manual page.
If the pathname given in
is relative, then it is interpreted relative to the directory
referred to by the file descriptor
(rather than relative to the current working directory of
the calling process, as is done by
for a relative pathname).
is relative and
is the special value
is interpreted relative to the current working
directory of the calling process (like
is absolute, then
is an empty string and the
flag is specified, then the file descriptor
specifies the file to be executed (i.e.,
refers to an executable file, rather than a directory).
argument is a bit mask that can include zero or more of the following flags:
is an empty string, operate on the file referred to by
(which may have been obtained using the
If the file identified by
and a non-NULL
is a symbolic link, then the call fails with the error
does not return.
On error, -1 is returned, and
is set appropriately.
The same errors that occur for
can also occur for
The following additional errors can occur for
is not a valid file descriptor.
Invalid flag specified in
and the file identified by
and a non-NULL
is a symbolic link.
The program identified by
requires the use of an interpreter program
(such as a script starting with "#!"), but the file descriptor
was opened with the
flag, with the result that
the program file is inaccessible to the launched interpreter.
is relative and
is a file descriptor referring to a file other than a directory.
was added to Linux in kernel 3.19.
GNU C library support is pending.
system call is Linux-specific.
In addition to the reasons explained in
system call is also needed to allow
to be implemented on systems that do not have the
When asked to execute a script file, the
that is passed to the script interpreter is a string of the form
is the number of the file descriptor passed via the
A string of the first form occurs when
A string of the second form occurs when the script is specified via both
in this case,
is the value given in
For the same reasons described in
the natural idiom when using
is to set the close-on-exec flag on
(But see BUGS.)
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
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at