Solved

About execl

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Read file descriptor 3 in C 14 107
First character of input string truncated with scanf 3 99
distributed computing in Python 4 124
Arduino EDI - Programming language 3 94
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
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 opening and reading files in the C programming language.

778 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