What is the difference between the functions of the exec family of system calls like exec and execve?

前端 未结 7 995
南笙
南笙 2020-12-13 06:17

I have been following a system programming course recently and I came through the system calls exec() and execve(). So far I cannot find a

7条回答
  •  隐瞒了意图╮
    2020-12-13 06:53

    Main Idea

    exec() family of functions replaces existing process image with a new process image. This is a marked difference from fork() system call where the parent and child processes co-exist in the memory.

    exec() family of functions

    int execv (const char *filename, char *const argv[])
    

    The filename is the file of the new process image.

    argv represents an array of null-terminated strings.The last element of this array must be a null pointer.

    int execl (const char *filename, const char *arg0, …)
    

    Same as execv but the arguments are provided as an individual string (separated by commas) instead of an array/vector.

    int execve (const char *filename, char *const argv[], char *const env[])
    

    Same as execv but it permits to specify environment variables for new process image.

    int execle (const char *filename, const char *arg0, …, char *const env[])
    

    Same as execl but it permits to specify environment variables for new process image.

    int execvp (const char *filename, char *const argv[])
    

    Same as execv function but it searches standard environment variable PATH to find the filename if the filename does not contain a slash.

    Here is a list of standard environment variable:

    https://www.gnu.org/software/libc/manual/html_node/Standard-Environment.html#Standard-Environment

    int execlp (const char *filename, const char *arg0, …)
    

    Same as execl function except the fact that if performs the filename search as the execvp function.

    Note

    In a Linux system, if you type env or printenv on the shell or terminal you will get a list standard environment variables.

提交回复
热议问题