I'm writting a C program in which I need some directory to be copied in the middle of the code. So I wrote this function, where I try to use fork and then execvp. However this code doesn't seem to enter pid==0, and is not less than 0 aswell. What can be wrong? I'm using minix if that matters
void execCopy() {
printf("I'm in execCopy\n");
printf("ERROR 0: %s\n",strerror(errno));
int pid = fork();
if(pid < 0) {
printf ("fork failed with error code= %d\n", pid);
fprintf(stderr,"FORK error\n");
}
printf("ERROR 1: %s\n",strerror(errno));
char *execArgs[] = { "cpdir", "-R", copy_path,paste_path, NULL };
printf("Copy from %s to %s\n",copy_path,paste_path);
if(pid == 0) {
printf("I'm gonna exec\n");
execvp("cpdir", execArgs);
printf("I should never get here \n");
}
else {
printf("I'm the father, going to return\n");
printf("ERROR 2: %s\n",strerror(errno));
return;
}
}
OUTPUT
Dec 26 20:34:11 192 kernel: I'm in execCopy
Dec 26 20:34:11 192 kernel: ERROR 0: Not a directory
Dec 26 20:34:11 192 kernel: ERROR 1: Not a directory
Dec 26 20:34:11 192 kernel: Copy from /./home to /./home/lcom
Dec 26 20:34:11 192 kernel: I'm the father, going to return
Dec 26 20:34:11 192 kernel: ERROR 2: Not a directory