I am writing a small shell program that takes a command and executes it. If the user enters a not valid command the if statement returns a -1. If the command is correct it exe
From man page of execvp(3)
The exec() family of functions replaces the current process image with a new process image
So your current process image is overwritten with the image of your command! Hence you need to use a fork+exec
combination always so that your command executes in the child process and your current process continues safely as a parent!
On a lighter note I want to illustrate the problem with a picture as a picture speaks a thousand words. No offence intended :) :)