execvp bad address

N

noelloen

hi,

I have the following code,

int ret;
char ** vector;
//vector[0] = "ls" vector[1] ="-al"
.....
//fork a child
......
ret= execvp(*temp, temp);

if( ret == -1)
perror(*vector);
.......

which works fine. and the child display the "ls -al"

But when I use the case "ls" alone, and "ls -a -l" it does not work,
and complains:

ls: Bad address
or
sometime gives
wrong args given

------- Failed Examples--------

kill %7182 //my input as child process
the temp[0] kill
the temp[i+1] %7182
parent: 6129 childtemp_pid 436
kill: %7182: no such job
/usr/bin/kill[8]: : Arguments must be %job or process ids

ps -u root //my input as child process
This is default case
the temp[0] ps
the temp[i+1] -u
the temp[i+1] root
parent: 3635 childtemp_pid 3639
ps: Bad address
This is default case
the temp[0] ls
the temp[i+1] -a
the temp[i+1] -l
parent: 3659 childtemp_pid 3660
ls: Bad address

only the following case works
ls -al
....runs and gives the output....


Since execvp does not require a path, I wonder what went wrong that it
does not see the bin executables, and if so why there is one case work?


Thank you very much.
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

noelloen said:
hi,

I have the following code,

int ret;
char ** vector;
//vector[0] = "ls" vector[1] ="-al"
Where is the space for vector[0] ?
All you have is an uninitialized pointer to pointer to char.

As the documentation for execvp (which is non
standard , ask in comp.unix.programmer for *nix specifics) ,
the argument list must end with a NULL pointer.
Consider e.g. char *vector[2] = {"-al",NULL};
 
N

noelloen

sorry about the confusion vector is temp ... i put the wrong name.
noelloen said:
hi,

I have the following code,

int ret;
char ** vector;
//vector[0] = "ls" vector[1] ="-al"
Where is the space for vector[0] ?
All you have is an uninitialized pointer to pointer to char.

As the documentation for execvp (which is non
standard , ask in comp.unix.programmer for *nix specifics) ,
the argument list must end with a NULL pointer.
Consider e.g. char *vector[2] = {"-al",NULL};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top