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

前端 未结 7 961
南笙
南笙 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 07:16

    Use man exec and read:

    The execv(), execvp(), and execvpe() functions provide an array of pointers to 
    null-terminated strings that represent the argument list available to the new program. 
    The first argument, by convention, should point to the filename associated with the file 
    being executed. The array of pointers must be terminated by a NULL pointer. 
    

    execv

    int execv(const char *path, char *const argv[]);
    

    So you pass an array as parameters

    int execle(const char *path, const char *arg,
                  ..., char * const envp[]);
    

    Almost the same, but not as an array, but rather as a list of values (strings), followed by an array the designates the environment.

    Here:

    int execvp(const char *file, char *const argv[]);
    

    You are calling a file, without path, so it expects you to be already in the right path before calling.

    Last but not least:

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

    Similar to previous one, but now you have two arrays, for arguments and environment variables.

    0 讨论(0)
提交回复
热议问题