Question: Add code to spawn a child process to execute the command using execvp() or execve(). You must create and pass a vector of pointers to
Add code to spawn a child process to execute the command using execvp() or execve(). You must create and pass a vector of pointers to the arguments.
#include #include #include #include #include char input; char* command; char* args; int childid; int PID; int main(int argc, char* argv[]) { int PID = getpid(); char input (60) ; char* command; char* args (60); while(1) { printf("%s", "Input a command or type q to quit "); fgets(input, 60, stdin); command = strtok( input," "); int i = 0; char* test; do{ test = strtok (NULL," , "); args[i] = test; i++; }while(strtok (NULL, " ") != NULL); args[i] = NULL; if(command [0] =='q' || command [@] == 'Q'){ break; }else{ childId = fork(); if (childid != PID && getpid() != PID ){ if(execvp(command, args) #include #include #include #include char input; char* command; char* args; int childid; int PID; int main(int argc, char* argv[]) { int PID = getpid(); char input (60) ; char* command; char* args (60); while(1) { printf("%s", "Input a command or type q to quit "); fgets(input, 60, stdin); command = strtok( input," "); int i = 0; char* test; do{ test = strtok (NULL," , "); args[i] = test; i++; }while(strtok (NULL, " ") != NULL); args[i] = NULL; if(command [0] =='q' || command [@] == 'Q'){ break; }else{ childId = fork(); if (childid != PID && getpid() != PID ){ if(execvp(command, args)