Exec Family

Library Required

1#include <unistd.h>

execl()

Replaces current process with a new one using a path and a list of arguments

1int execl(const char *path, const char *arg, ..);

Return Values:

  • Success: No return
  • Error: -1

Example:

1execl("/bin/ls", "ls", "-l", NULL);

execlp()

Like execl() but searches PATH for the executable

1int execlp(const char *file, const char *arg, ..);

Return Values:

  • Success: No return
  • Error: -1

Example:

1execlp("ls", "ls", "-l", NULL);

execle()

Like execl() but allows specifying a custom environment

1int execle(const char *path, const char *arg, .., char * const envp[]);

Return Values:

  • Success: No return
  • Error: -1

Example:

1char *env[] = { "MYVAR=VALUE", NULL };
2execle("/bin/ls", "ls", "-l", NULL, env);

execv()

Replaces current process using a path and an argument vector (array)

1int execv(const char *path, char *const argv[]);

Return Values:

  • Success: No return
  • Error: -1

Example:

1char *args[] = { "ls", "-l", NULL };
2execv("/bin/ls", args);

execvp()

Like execv() but searches PATH for the executable

1int execvp(const char *file, char *const argv[]);

Return Values:

  • Success: No return
  • Error: -1

Example:

1char *args[] = { "ls", "-l", NULL };
2execvp("ls", args);

execvpe()

Like execvp() but also allows specifying a custom environment

1int execvpe(const char *file, char *const argv[], char *const envp[]);

Return Values:

  • Success: No return
  • Error: -1

Example:

1char *args[] = { "ls", "-l", NULL };
2char *env[] = { "MYVAR=VALUE", NULL };
3execvpe("ls", args, env);
Last updated on