What are the different versions of exec used for in C and C++?

C++CExec

C++ Problem Overview


These are all the versions of exec that can be used in C (and C++)

execl
execle
execlp
execv
execve
execvp

What's the difference between them? How do you know which one to use?

C++ Solutions


Solution 1 - C++

The differences are combinations of:

  1. L vs V: whether you want to pass the parameters to the exec'ed program as

    • L: individual parameters in the call (variable argument list): execl(), execle(), execlp(), and execlpe()
    • V: as an array of char* execv(), execve(), execvp(), and execvpe()

    The array format is useful when the number of parameters that are to be sent to the exec'ed process are variable -- as in not known in advance, so you can't put in a fixed number of parameters in a function call.

  2. E: The versions with an 'e' at the end let you additionally pass an array of char* that are a set of strings added to the spawned processes environment before the exec'ed program launches. Yet another way of passing parameters, really.

  3. P: The versions with 'p' in there use the environment variable PATH to search for the executable file named to execute. The versions without the 'p' require an absolute or relative file path to be prepended to the filename of the executable if it is not in the current working directory.

Solution 2 - C++

Opengroup are one of the best general references for core c/c++ functions.

The docs for exec* are here: http://pubs.opengroup.org/onlinepubs/009695399/functions/environ.html

Solution 3 - C++

It's Posix extension of C runtime library. If official Posix documentation is insufficiently then I can recomend book - Samuel P. Harbison, Guy L.Steele, 2002 "C A Reference" Page# 416 - cover that question.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionnode ninjaView Question on Stackoverflow
Solution 1 - C++ChristoView Answer on Stackoverflow
Solution 2 - C++IanNortonView Answer on Stackoverflow
Solution 3 - C++Konstantin BurlachenkoView Answer on Stackoverflow