By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,243 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

execvp bad address

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.