Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

About execl

Posted on 2006-10-29
3
Medium Priority
?
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Accepted Solution

by:
Mysidia earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
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 how to create, access, and change arrays in the C programming language.

618 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