Jerrico Kyle
Jerrico Kyle

Reputation: 154

Unsure how to Parse arguments and utilise excevp function

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 ,

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

Answers (1)

dbush
dbush

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

Related Questions