Linux Process Creation II (EXECVE)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.