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
Solved

About execl

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Picking random number 8 178
Read file descriptor 3 in C 14 112
List out all word 7 317
placing a checked in the checklistbox based on the value in database table. 3 20
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

856 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