为什么要首先将execve()的arg设置为可执行文件的路径

编程入门 行业动态 更新时间:2024-10-25 10:31:02
本文介绍了为什么要首先将execve()的arg设置为可执行文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道execve()和family要求其参数数组的第一个参数与也由其第一个参数指向的可执行文件相同.也就是说,在此:

I understand that execve() and family require the first argument of its argument array to be the same as the executable that is also pointed to by its first argument. That is, in this:

execve(prog, args, env);

args [0]通常与prog相同.但是我似乎找不到有关为什么的信息.

args[0] will usually be the same as prog. But I can't seem to find information as to why this is.

我还了解到,可执行文件(至少是shell脚本)在运行时始终将其调用路径作为第一个参数,但是我认为shell会做一些工作来将其放在那里,而execve()只会使用其第一个参数(上面的"prog")中给出的路径调用可执行文件,然后像在命令行上那样传递参数数组(上面的"args")..即,我不调用脚本在命令行中,在args列表中有重复的可执行路径....

I also understand that executables (er, at least shell scripts) always have their calling path as the first argument when running, but I would think that the shell would do the work to put it there, and execve() would just call the executable using the path given in its first argument ("prog" from above), then passing the argument array ("args" from above) as one would on the command line.... i.e., I don't call scripts on the command line with a duplicate executable path in the args list....

/bin/ls /bin/ls /home/john

有人可以解释吗?

推荐答案

它允许您指定要加载的可执行文件的确切路径,但也可以在诸如之类的工具中显示美化"名称.> ps 或 top .

It allows you to specify the exact path to the executable to be loaded, but also allows for a "beautified" name to be presented in tools such as ps or top.

execl("/bin/ls", "ls", "/home/john", (char *)0);

更多推荐

为什么要首先将execve()的arg设置为可执行文件的路径

本文发布于:2023-11-24 03:38:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623838.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设置为   可执行文件   路径   execve   arg

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!