Linux execlp function Using basic tutorials

  
 Execlp looks for a file from the PATH environment variable and executes the definition: int execlp(const char * file, const char * arg, ……); header file: #include<unistd.h> Description: execlp() will be from the PATH environment Find the file name that matches the parameter file in the directory pointed to by the variable. After the file is found, execute the file, and then use the second and subsequent parameters as argv[0], argv[1]……, the last parameter of the file. Must end with a null pointer (NULL). Return value: If the execution is successful, the function will not return. If the execution fails, it will return -1 directly. The reason for the failure is stored in errno. Related functions: fork, execl, execle, execv, execve, execvp error code: refer to execve(). Example:

#include<unistd.h>

main(){execlp("ls","ls","-al","/zhmc",(char *) 0);

}

Output:



Copyright © Windows knowledge All Rights Reserved