107

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?

3 Answers 3

212

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.

0
5

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

2
  • 3
    this doesn't really answer the question and is link only. Apr 9, 2018 at 15:31
  • Before arriving here, I read the documentation on the website, but it did not help a lot. The explanations are very short, even though they should be elaborate. Additionally, it is hard to find the correct explanation for what you are looking for, if you are searching from scratch.
    – Akito
    Oct 2, 2020 at 12:44
-4

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.

3
  • 3
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – 31piy
    Dec 14, 2017 at 5:17
  • The links was to amazon and to posxis standart to be usefull for reader. Ok, I removed links as you asked, even I disagree that this is better. Remve your donwvote if now it's more readable. Dec 14, 2017 at 23:29
  • 2
    I didn't downvote for your answer. I just had my review on your answer, which I thought was of low quality. I didn't mean to remove the links. The point here is to include relevant excerpts from the link which helps the future readers to understand the answer instantly. Just posting the links in the answer doesn't help anyone.
    – 31piy
    Dec 15, 2017 at 3:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.