I have some code that works. However, when I try to make it not work (i.e. try to execute a non-existent program), I don't see any indication that it hasn't worked. Here's the code snippet.
pid_t pid;
// char *const paramList[] = {"/usr/threshold/bin/preconfig.sh", options[indexSelected].optionName, NULL};
const char* paramList[] = {"doesNotExist", "-r", NULL};
printf ("Forking\n");
if ((pid = fork()) == -1)
{
printf ("pid == -1\n");
printf ("Error : Program did not fork correctly.");
}
else if (pid == 0)
{
printf ("pid == 0\n");
execvp(paramList[0], paramList);
printf("Error : execvp did not execute successfully.\n");
}
printf ("Program done");
return 0;
Line 2 is the real executable. Uncomment line 2 and comment line 3 and everything works great. The program in line 2 exists and I have seen by the files that it changed that it has executed successfully.
Comment out line 2 and uncomment line 3 and that changes it to make an execvp call to a non-existent program. I expected line 15 to display. However, it did not display.
Does anyone know why? I need some way of knowing whether my call to the program was successful. Thanks.