Xun is the basic exec function family of i.MX6ULL Terminator process

After the fork function is used to create a child process, the child process often needs to call an exec function to execute another program. The child process is replaced by the new program, changing the address space, process image and some attributes, but the pid number remains unchanged.
execve():
#include
int execve(const char *filename, char *const argv[], char *const envp[]);
Parameter meaning:
filename: path name, which means the new program path loaded into the process space.
argv[]: command line parameter, argv[0] is the command name.
envp[]: The environment variables of the new program.
Return value: It will not return when it succeeds. It is not necessary to check the return value when using it, but can be checked by errno.
The following functions are implemented according to execve:
int execl(const char *path, const char arg, …/ (char *) NULL */);
int execlp(const char *file, const char arg, …/ (char *) NULL */);
int execle(const char *path, const char arg, …/, (char *) NULL, char * const envp[] */);
int execv(const char *path, char *const argv[]) ;
int execvp(const char *file, char *const argv[]);
int execvpe(const char *file, char *const argv[],char *const envp[]);
Experimental code:
create a child process, the child process uses execl to call ls to view the files in the current directory.
exec.c:
Use execl to call shell commands to view file information.


Execution result:

Linux system implements functions such as "popen" and "system" based on these functions, which can directly call functions such as shell.

Guess you like

Origin blog.csdn.net/mucheni/article/details/114696698