468,513 Members | 1,759 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

execvp bad address

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
ls -a -l
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.

Sep 26 '06 #1
2 10875
noelloen wrote:
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};
Sep 26 '06 #2
sorry about the confusion vector is temp ... i put the wrong name.

Nils O. Selåsdal wrote:
noelloen wrote:
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};
Sep 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by mikeSpindler | last post: by
reply views Thread by Kevin Smith | last post: by
1 post views Thread by s99999999s2003 | last post: by
5 posts views Thread by ws.taylor | last post: by
3 posts views Thread by Thomas Guettler | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.