|

楼主 |
发表于 2005-5-24 13:08:02
|
显示全部楼层
Post by jovesky
整个过程是这样的吧:
对于
- int
- main(void)
- {
- execl("/home/kiron/testexec", "testexec", "arg1", "arg2", (char *) 0);
- return 0;
- }
复制代码
就是形成执行序列:/home/kiron/testexec testexec arg1 arg2。然后/home/kiron/testexec在被替换为/home/kiron/showargs addargs,也就是形成了:
/home/kiron/showargs addargs testexec arg1 arg2。
那么为什么最后testexec变成了/home/kiron/testexec啊。还有,如果我把
execl("/home/kiron/testexec", "testexec", "arg1", "arg2", (char *) 0);改成
execl("/home/kiron/testexec", (char *) 0);的话,/home/kiron/testexec还是会输出的。这时后的执行序列不是变成/home/kiron/showargs addargs了吗,为什么还有/home/kiron/testexec呢?
其实也就是你最初“卖关子”没说的地方最后我还是没看明白。
麻烦斑竹大人帮忙再解释一下下。。
哦。。。
我明白你哪里出错了
平常我们传递main(int argc, char **argv)中参数大家都觉得会很平常
现在我们用exec族函数传递给可执行程序的main的参数也是exec中的一些参数,
我这里说的加上execl参数列表中指定的参数列表是指execl传递给可执行程序的参数列表。
像execl("/home/kiron/testexec", "testexec", "arg1", "arg2", (char *) 0);
相当于/home/kiron/testexec arg1 arg2
注意:少了execl中的第二个参数testexec
另外请man execl |
|