Reputation: 154
I am trying to write a Program called Generate that basically creates a child process to execute a particular process and print some statistics with regard to the execution of the process
Suppose my input on the terminal is ./Generate ./a 123 234
,
main(int args, char **argv)
.argv[0]
= ./Generate , argv[1]
, =./a , argv[2]
= 123 , argc[3]
= 1234.execvp()
, to execute ./a 123 234.
How would I go about doing the same Example:
if (pid == 0){
execvp(a[0],a); // I want 'a' here to contain my input
Upvotes: 0
Views: 58
Reputation: 225827
Assuming that all parameters pass to your program are the command line of the program to invoke, you can do the following:
execvp(argv[1], &argv[1]);
Since argv
is an array of pointers, &argv[1]
gives you a pointer to the second element in that array, so the remaining elements will follow.
Upvotes: 1