Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

execv, execl

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
What is the proper syntax for creating a new process in the following C program:

char* file_name;
file_name = argv[1];
if (fork==0)
execv (file_name, &argv[1] ?? )

This C program is called myprocess and the syntax is as follows:

myprocess (program_to_execute) [arg1, arg2...argn]

(i.e. "myprocess" should pass the argument list that is given to it to the "program_to_execute" in the execv call so that the "program_to_execute" uses them. This list of arguments must be of arbitrary length.
 
from memory .. this works if file_name is fully qualified (such as /usr/local/bin/myprocess); if you want the shell to do a PATH search, then you probably need to use execvp.

&argv[1] looks OK and can be any length, providing argv is terminated by a null pointer. This is true if you are simply passing on the argument list that has been passed.

I'll qualify this by saying it has been a couple of years since doing this sort of thing, so apologies if it's wrong.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top