Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 C 程序中,主函数通过查看 argc 来知道在 argv 中传递了多少参数。我似乎不清楚系统调用 execve 如何知道传递给它的参数数量。有人可以帮助解释 execve 如何处理参数吗?
我最近的 Linux 系统上的文档execve说:
execve
argv 是传递给新程序的参数字符串数组。envp 是一个字符串数组,通常采用 key=value 的形式,作为环境传递给新程序。 argv 和 envp 都必须以空指针终止。 参数向量和环境可以被调用程序的主函数访问,当它被定义为: int main(int argc, char *argv[], char *envp[])
argv 是传递给新程序的参数字符串数组。envp 是一个字符串数组,通常采用 key=value 的形式,作为环境传递给新程序。 argv 和 envp 都必须以空指针终止。 参数向量和环境可以被调用程序的主函数访问,当它被定义为:
int main(int argc, char *argv[], char *envp[])
我把重要的部分加粗了。argv列表末尾必须有一个空指针。内核将对参数进行计数并将计数作为argc.
argv
argc