execl is a one of the family of exec calls which act as front end to the execve.
In the post "Using execve" we saw how it can be used to launch a new process and also pass arguments to it. execl also launches a new process replacing the current one. The syntax of execl is
In execve we had to pass an array of pointers as argument, but in execl we can directly pass the pointers as arguments. These arguments should be NULL terminated.
Example:
Let us write a simple program to print the arguments passed to it.
hello.c:
By convention the first argument should always be the filename and we will be following the same.
Let us compile this and name the executable as "hello"
Now let us write a program to run the executable "hello" using execl.
execl.c
Compile the code and execute it.
Output:
Thus the program could successfully run the executable "hello" and also pass the arguments to it.
Also note that execl did not return to the calling function,else it would have printed the "Error" statement after the call to execl.
In the post "Using execve" we saw how it can be used to launch a new process and also pass arguments to it. execl also launches a new process replacing the current one. The syntax of execl is
In execve we had to pass an array of pointers as argument, but in execl we can directly pass the pointers as arguments. These arguments should be NULL terminated.
Example:
Let us write a simple program to print the arguments passed to it.
hello.c:
By convention the first argument should always be the filename and we will be following the same.
Let us compile this and name the executable as "hello"
Now let us write a program to run the executable "hello" using execl.
execl.c
Compile the code and execute it.
Output:
Thus the program could successfully run the executable "hello" and also pass the arguments to it.
Also note that execl did not return to the calling function,else it would have printed the "Error" statement after the call to execl.
No comments:
Post a Comment