15

I use execv instead of execl. To use execv, I create an array and put arguments that I use with execl in there. Then I put this array into execv

I know I have to use an array of arguments for execv but why? What is the difference between execl and execv?

cwd
  • 53,018
  • 53
  • 161
  • 198
Ahmet Tanakol
  • 241
  • 1
  • 7
  • 13
  • 1
    Possible duplicate of [What are the different versions of exec used for in C and C++?](https://stackoverflow.com/q/5769734/608639) – jww Apr 18 '19 at 11:22

1 Answers1

14

There is no difference other than the format of the arguments. They will both end up calling the same underlying system call execve().

mark4o
  • 58,919
  • 18
  • 87
  • 102
  • Why do we need the change the format of the arguments? I mean if they are doing same thing – Ahmet Tanakol Feb 03 '12 at 04:35
  • 2
    The `execve()` system call (and `execv()`) take the arguments in an array. `execl()` is just provided as a convenience, in case you have a fixed number of arguments, to allow you to avoid the trouble of setting up an array. `execl()` will store the function arguments in a temporary array itself and then make the system call. If you set up the argument array yourself then you have no need for `execl()`. – mark4o Feb 03 '12 at 04:40
  • Here is an example: https://stackoverflow.com/a/32142863 – mig001 Feb 26 '22 at 02:53