execl的()在Ubuntu参数 [英] execl() arguments in Ubuntu

查看:120
本文介绍了execl的()在Ubuntu参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习linux编程和跨exec函数这是一种非常有用的来了。但问题是执行函数的参数都非常混乱,我无法掌握这些参数是出于什么目的。在下面的code EXECL()函数被调用从通过创建一个子叉(),什么是最后一个参数的目的<$ C( NULL ) $ C> EXECL()?

I am learning linux programming and came across exec function which is kind of very useful. But the problem is exec function arguments are very confusing and I am unable to grasp which argument is for what purpose.. In the following code execl() function is called from a child created through fork(), What is the purpose of the last argument (NULL) in execl()?

execl("/bin/ls","ls","-l",NULL);

如果任何人能解释什么是目的 NULL 参数和其他参数和执行exec()参数的目的家庭功能,这将是一个对我帮助很大!

If any one can explain what is the purpose of NULL argument and other arguments and the purpose of arguments of exec() family function, It would be a great help to me!

推荐答案

要创建未定义的行为。这不是 EXECL 法律调用。一个
正确的调用可能是:

To create undefined behavior. That is not a legal call to execl. A correct call might be:

execl( "/bin/ls", "ls", "-l", (char*)0 );

最后一个参数的必须的是(的char *)0 ,或具有不确定的行为。
第一个参数是可执行文件的路径。下列
参数出现在的argv 执行的程序。这些名单
参数被终止(的char *)0 ;这是如何被调用的函数
知道最后的参数已经达到了。在上面的例子中,
例如,在可执行文件/斌/ LS将取代你的code;在
,它将有 ARGC 等于2,用的argv [0] 等于LS
的argv [1] 等于 - 1。

The last argument must be (char*)0, or you have undefined behavior. The first argument is the path of the executable. The following arguments appear in argv of the executed program. The list of these arguments is terminated by a (char*)0; that's how the called function knows that the last argument has been reached. In the above example, for example, the executable at "/bin/ls" will replace your code; in its main, it will have argc equal 2, with argv[0] equal "ls", and argv[1] equal "-l".

此功能后,立即,你应该有错误处理
code。 ( EXECL 总是返回-1,当它返回,所以你不需要
测试它。而且它只返回,如果有某种错误。)

Immediately after this function, you should have the error handling code. (execl always returns -1, when it returns, so you don't need to test it. And it only returns if there was some sort of error.)

这篇关于execl的()在Ubuntu参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆