execvp

Executes the file pointed to by the file parameter.

Library:LibC
Classification:POSIX
Service:General C Services

Syntax

  #include <unistd.h>
  
  int execvp (
     const char   *file,
     char *const   argv[]);
  

Parameters

file

Points to a file to execute.

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.

Return Values

If an error occurs, returns -1 and sets errno 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.

If the file parameter does not contain a slash (/) character, execvp duplicates the shell by searching for an executable file. It uses the search path specified in the environment by the PATH variable. If this variable is not specified, the default path :/bin:/usr/bin is used.

If permission is denied for a file, execvp continues searching the rest of the search path. If no other file is found, it returns -1 and sets errno to EACCES.

If a file header is not recognized, execvp executes the shell with the path of the file as its first parameter. If this attempt fails, it stops searching.

The execvp function uses the environ external variable as the environment for the new process.

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

See Also