Invoke shell script commands: execlp("sh","sh","filename",(char*)0);
exec completely replaces the image of the program that called it with the program being executed. Fork creates a new process and generates a new PID. exec starts a new program and replaces the original process. Therefore, the PID of the new process executed by exec will not change, just like the process of calling exec.
int exec…Load and run other programs: int execl( char *pathname,char *arg0,char *arg1,...,char *argn,NULL)int execle( char *pathname,char * Arg0,char *arg1,...,char *argn,NULL,char *envp[])int execlp( char *pathname,char *arg0,char *arg1,...,NULL)int execlpe(char *pathname, Char *arg0,char *arg1,...,NULL,char *envp[])int execv( char *pathname,char *argv[])int execve( char *pathname,char *argv[],char *envp[ ,null,null,3],]) int execvp( char *pathname, char *argv[])int execvpe(char *pathname,char *argv[],char *envp[]) The exec family of functions loads and runs the program pathname and sets the argument arg0(arg1 , arg2, argv[], envp[]) passed to the subroutine, the error returns -1 in the exec function family, the suffix l, v, p, e is added to the exec, the specified function will have some operational ability When the suffix is p, the function can use the PATH variable of DOS to find the subroutine file. If you want to execute the command /bin/cat /etc/passwd /etc/group,l, you want to receive a comma-separated list of arguments, with the NULL pointer as the end marker execl( "/bin/cat","/Etc/passed","/etc/group",NULL);v, you want to receive a pointer to a NULL-terminated string array char* argv[] = {"/bin/cat","/Etc/passed","/etc/group",NULL}execv( "/bin/cat", argv );e, the function passes the specified parameter envp, allowing the environment of the child process to be changed, without the suffix e The process uses the environment of the current program. Envp is also a NULL-terminated string array pointer execl (execution file) related functions fork, execle, execcl, execv, execve, execvp header file #include<unistd.h> define function int execl(const char * path, const Char * arg,....); Function Description execl() is used to execute the file path represented by the parameter path string. The next parameter represents the passed argv(0), argv[1]&hellip when the file is executed. ;…, the last argument must end with a null pointer (NULL). The return value will not return if the execution is successful. If the execution fails, it will return -1 directly. The reason for the failure is stored in errno. Example #include<unistd.h>main(){execl(“/bin/ls”,”ls”,”-al”,”/etc/passwd”,(char * )0);}Execute /*Execute /bin/ls -al /etc/passwd */-rw-r--r-- 1 root root 705 Sep 3 13 :52 /etc/passwd
execlp (from the PATH environment variable Find the file and execute) related functions fork, execl, execle, execv, execve, execvp header file #include<unistd.h> define function int execlp(const char * file, const char * arg, ……); Explain that execlp() will look for the file name that matches the parameter file from the directory pointed to by the PATH environment variable. After the file name is found, the file will be executed, and the second and subsequent parameters will be treated as argv[0], argv[1] of the file. ……, the last argument 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. The error code refers to execve(). Example /* Executing ls -al /etc/passwd execlp() will find /bin/ls */#include<unistd.h>main(){execlp(“ls”,”ls&rdquo) depending on /bin in the PATH variable ;,”-al”,”/etc/passwd”,(char *)0);}Execute -rw-r--r-- 1 root root 705 Sep 3 13 :52 /etc/passwd
execv (execution file) related functions fork, execl, execle, execcl, execve, execvp header file #include<unistd.h> define function int execv (const char * path, char * const argv[ ]); function The execv() method is used to execute the path of the file represented by the parameter path string. The difference from execl() is that execve() takes only two parameters, and the second parameter is passed to the executable file using the array pointer. 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. Please refer to execve() for the error code. Example /* Execute /bin/ls -al /etc/passwd */#include<unistd.h>main(){char * argv[ ]={“ls”,”-al”,”/etc/Passwd”,(char*) }};execv(“/bin/ls”,argv);}Execute -rw-r--r-- 1 root root 705 Sep 3 13 :52 /etc/passwd
execve (execute file) related functions fork, execl, execle, execcl, execv, execvp header file #include<unistd.h> define function int execve(const char * filename, char * const argv[ ], char * Const envp[]); function description execve () is used to execute the file path represented by the parameter filename string, the second parameter is passed to the executable file using the array pointer, argv is passed to the program's complete parameter list, including argv [0], which is typically the name of the executing program; the last parameter is an array of new environment variables passed to the executable. 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. Error code EACCES1. The file to be executed does not have the user-executable permissions. 2. The file system to which the file to be executed belongs is suspended in noexec mode. 3. The file or script translator to be executed is not a general file.
According to foreign media reports, Linux does not seem to be fully loved by people. Operating syste
When dealing with Oracle problems in the actual production environment, sometimes you need a remote
Problem Description Solution Reasons for analysis, maybe because my platform migr
I. Manually compile and install 1, download the installation package, wget https://ohse.de/uwe/rele
What is the relationship between Linux and GNU?
Current sinking, current sinking, sinking current, pull-up resistor, high resistance state analysis
Linux DDOS attack on Windows system
CentOS configuration ssh system technology
Analysis of PCB software tools under Linux
Log all IP user operation logs by login IP
ARM ADS assembly and Gnu assembly conversion
Awk operator (arithmetic operator, assignment operator, relational operator, logical operator,
Windows 8 flexible split screen snap function
What is the Win7 system shutdown shortcut and restart shortcut?
How to identify the genuine Microsoft win7 system disc method
What should I do if the Win10 9926 app store says "Cannot be used in your country?"
How to close the default LAN shared folder function of the win7 system
Search is not available after Win7 upgrade Win10? The culprit has been exhausted
The file explorer on the Win10 taskbar has disappeared. How to retrieve
How WinXP uses Media Player to view pictures
Master teaches you to recover the cheats of accidentally deleted files