Three: Execve system call int execve (constchar char *const argv[],char *Const envp[]); Fork creates a new process that produces a new pidexecve that completely replaces the image of the calling process with the executed program. EXECVE starts a new program and replaces the original process, so the PID of the executed process does not change. The EXECVE function accepts three parameters - The full path of the file to be executed by path --ARGV passed to the program completion parameter list, including argv[0], It is usually the name of the executing program, the last parameter is generally null--ENVP is the environment pointer to the execution of the execed program, and is generally set to null
//definition of the EXECVE function#include <stdio.h>#include<stdlib.h>#include<string.h>#include<errno.h>#include<unistd.h>intMainintArgChar*args[]) { /*The first parameter is the name of the program, the second parameter is the parameter of the called program, and the last argument must be null, which is similar to the parameter of the main function, the args array .*/ Char* argv[]={"/bin/ls","- L", NULL}; Execve ("/bin/ls", Argv,null); /*The Execve function replaces the original program code, but the process PID does not change, the file descriptor does not change, but the program code is replaced, so the statements after the EXECVE function are not executed*/printf ("Program is end!\n"); return 0;}
Linux Process Creation II (EXECVE)