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
?
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.
Description: The execl() function replaces the current process image with a new process image specified by path. The new image is constructed from a regular, executable file called the new process image file. No return is made because the calling process image is replaced by the new process image.
execve() is a POSIX (and UNIX systems in general) function of the family of the exec*() functions that replace the current process image. The v comes from the fact that it takes an argument argv to the vector of arguments to the program (the same way the main function of a C program may take it).
The execl function is most commonly used to overlay a process image that has been created by a call to the fork function. is the filename of the file that contains the executable image of the new process. is a variable length list of arguments that are passed to the new process image.
There is no difference other than the format of the arguments. They will both end up calling the same underlying system call execve()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With