I am having trouble creating a child process, and I'm not sure if I have the execvp argument right. Is there a way to fix it so it'll pass correctly?
int execute(char* input) {
int i = 0;
char* shell_argv[MAX_CMD_LINE_ARGS];
memset(shell_argv, 0, MAX_CMD_LINE_ARGS * sizeof(char));
//passing pointer of input and element list 128
int shell_argc = parse(input, shell_argv);
int status = 0;
pid_t pid = fork();
if (pid < 0) {
fprintf(stderr, "Fork() failed\n"); } // send to stderr
else if (pid == 0) { // child
// fill in code for execvp(...) <- this is what I'm having trouble with
if (execvp(shell_argv[0], shell_argv) == -1 && strcmp(input, "history") != 0) {
printf("Invalid command\n");
}
} else { // parent ----- don't wait if you are creating a daemon (background) process
while (wait(&status) != pid) { }
}
return 0;
}