Solved

About execl

Posted on 2006-10-29
3
190 Views
Last Modified: 2010-04-15
Is there a different between this two commands(second just repeat the /bin/ls)?which is correct?

execl("/bin/ls","/bin/ls","-a","-l",0);
execl("/bin/ls","-a","-l",0);
0
Comment
Question by:william007
3 Comments
 
LVL 23

Accepted Solution

by:
Mysidia earned 500 total points
ID: 17829521
The first is what probably does what you expect.

The binary you execute, and the name you tell it it is running as, the argv[0], are two different things.

You could run  execl("/bin/cat", "asdfxyz123", NULL);

The program that 'cat' will think is running and will appear in the system process list will be that argv[0], "asdfxyz123".


> execl("/bin/ls","/bin/ls","-a","-l",0);

Passes execution to ls, inside of the LS command...
argv[0] = /bin/ls
argv[1] = -a
argv[2] = -l

So  "/bin/ls" is the program name that /bin/ls will see itself run as and will appear in the ps list
-a is the first command line parameter
-l is the second command line parameter

Second case...
> execl("/bin/ls","-a","-l",0);

Passes execution to /bin/ls, inside of the LS command...
argv[0] = -a
argv[1] = -l

So "-a" is the program name that /bin/ls will see itself run as and will appear in the ps list as the program name
-l is the first command line parameter.

(-a will probably not be processed as a parameter, most programs won't use argv[0] for anything special)
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 17829607
For these kind of questions, always check the manual page for the function in question :

    man execl

http://unixhelp.ed.ac.uk/CGI/man-cgi?execl+3
0
 
LVL 9

Author Comment

by:william007
ID: 17853553
Thanks=)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now