I am trying to implement a program that concurrently runs a list of executables specified as command line arguments, considering the executables without any arguments of their own. The program should wait for the end of the execution of all processes created by itself.
I can only use these functions to execute:
int execl(const char*path, const char*arg0, ..., NULL);
int execlp(const char*file, const char*arg0, ..., NULL);
int execv(const char*path, char*const argv[]);
int execvp(const char*file, char*const argv[]);
This is what I've created so far:
void main (int args , char **s) {
int i , x , status;
if (args >= 2) {
x = fork ();
for ( i = 1 ; i < args ; i++) {
if (x == 0) {
execvp (s[i],&s[i]);
x = fork();
}
else
{
wait (&status);
_exit(i);
}
}
}
_exit(0);
}
But the program only executes the first argument of main
.
How can I change the code to do what I want?