为什么我们在 execlp() 的前 2 个参数中传递相同的值

pan*_*aha 5 c exec

以下是函数声明:

int execlp(const char *file, const char *arg, ...);
Run Code Online (Sandbox Code Playgroud)

以下是参数说明:

file: The executable that has to be executed by  the new process. This executable is searched for in the path specified by the environmental variable PATH. 

*arg,...: list of arguments terminated by a NULL argument.
Run Code Online (Sandbox Code Playgroud)

那么为什么我们这样调用函数:

execlp("ls","ls",NULL);
Run Code Online (Sandbox Code Playgroud)

它不会变成 "ls -ls" ,这是什么意思?

小智 4

第一个是要加载执行的二进制文件。第二个是进程的名称(例如在 的输出中显示的名称ps)。它们相同是很常见的,但这不是必需的。

因此,在 执行的二进制文件中exec*(),您为进程指定的名称可用作argv[0]