execve

Executes the program pointed to by the path parameter.

Library:LibC
Classification:POSIX
Service:General C Services

Syntax

  #include <unistd.h>
  
  int execve (
     const char   *path,
     char *const   argv[],
     char *const   envp[]);
  

Parameters

path

Points to the path of a file to execute. The executable file must be either a binary executable or a script (with a maximum line length of 127 characters) starting with a line in the following format:

  #1 interpreter [arg]
  

The interpreter must be a valid pathname for an executable file, which is invoked as

  interpreter [arg] filename
  
argv

Points to an array of null-terminated strings that represent the parameter list that is available to the new program. The first array entry points to the file name that is associated with the file to execute. The array must be null terminated.

envp

Points to an array of null-terminated strings, usually in the form key=value, that represent the environment of the program to execute. This array must be terminated by a NULL pointer.

Return Values

If an error occurs, returns -1 and errno is set to indicate the error. Otherwise, nothing is returned.

Decimal

Constant

Description

1

ENOENT

The file, script, or ELF interpreter does not exist or a shared library needed for the file or interpreter cannot be found.

2

E2BIG

The parameter list is too big.

3

ENOEXEC

The executable is not in a recognized format, is for the wrong architecture, or has some other format error that means it cannot be executed.

5

ENOMEM

Not enough kernel memory exists.

6

EACCES

The file or script interpreter is not a regular file; you don't have execute permission for the file, script, or ELF interpreter; the file system is mounted as noexec; or you don't have search permission for the file or script interpreter.

9

EINVAL

An ELF executable has more than one PT_INTERP segments (because it tried to name more than one interpreter).

10

ENFILE

The limit on the total number of files open on the system was reached.

11

EMFILE

The process has the maximum number of files open.

27

EFAULT

The file points outside your accessible address space.

28

EIO

An I/O error occurred.

64

EISDIR

An ELF interpreter was a directory.

65

ENAMETOOLONG

The file name is too long.

67

ENOTDIR

A component of the path prefix of the file, script, or ELF interpreter is not a directory.

69

EPERM

The file system is mounted as nosuid, the user is not the superuser, and the file has an SUID or SGID bit set. The process is being traced, the user is not the superuser, and the file has an SUID or SGID bit set.

85

ELOOP

There are too many symbolic links in the file, script, or ELF interpreter.

Remarks

IMPORTANT:This function is only available to NLMs that link with the POSIX semantics flag and load into protected address space (ring3). If these requirements are not met, errno is set to ENOSYS.

The execve function overwrites the text, data, and stack of the calling process with those of the new program. It also clears any pending signals and sets any signals that are set to be caught by the calling process back to their default behavior. When the SIGCHLD signal is set to SIG_IGN, it can be reset to SIG_DFL.

The executed program inherits the PID of the calling process and any open file descriptors that are not set to close when the exec functions run. For any open file descriptors, all attributes remain unchanged.

If the executed program is being ptraced, SIGTRAP is sent after the execve function returns successfully.

If the set-uid bit is set on the new program file, the effective user ID of the calling processed is changed to be the same as the owner of the program file. Similarly, when the set_gid bit of the file is set, the effective group ID of the calling process is set to the group of the program file.

The number of bytes available for the combined parameters of the new process and the environment lists is defined by ARG_MAX.

See Also