Solved

About execl

Posted on 2006-10-29
3
183 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

706 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

18 Experts available now in Live!

Get 1:1 Help Now