I am trying to execute a file using fork
and execvp
, however I am encountering some errors. I have not found any solutions to the problem I am having here online, since I don't get any errors from my exevp nor does it run. Here is my code:
pid_t child;
int status;
child = fork();
char *arg[3] = {"test","/home/ameya/Documents/computer_science/cs170/project1", (char*) 0};
if(child == 0){
printf("IN CHILD BEFORE EXECVP\n");
int value = execvp(arg[0],arg);
if(value < 0){
printf("ERROR\n");
}else{
printf("In Child : %i\n", value);
}
}
if(waitpid(child, &status, 0) != child){
printf("ERROR IN PROCESS\n");
}
printf("In Parent\n");
When I try to run this code it only outputs the "IN CHILD BEFORE EXCEPTION" and "IN PARENT" it doesn't print out any of the printf statements in between why does it do that. The file I am trying to run a simple executable that prints "hello world" to stdout.
Thanks for any help