Reputation: 63
I want to write a program that uses exec in order to mutate a child and use it to do a curtain action.
The child has to calculate a simple equation (-,+,*,/).
When I try to access the file using execvp
I get the following error:
execvp() failed!: Permission denied
Anyone has an idea what have I done wrong? Here is my code down below.
int main()
{
signal(SIGCHLD, SIG_IGN); //ignore child signal from now on
pid_t status;
char *a[2] = { "calculator", "2+1", NULL };
status = fork();
if (status != 0)
{
do_child(0, a);
}
return EXIT_SUCCESS;
}
/*
* id 0: calculator
* id 1: factorial
* id 2: pid
*/
void do_child(int id, const char *args[])
{
switch (id) {
case 0:
if (execvp("../ex2cFactorial/ex2cCalculator.c", args) != 0)
{
perror("execvp() failed!");
exit(EXIT_FAILURE);
}
break;
//other cases (haven't been written yet)
}
}
Upvotes: 0
Views: 2145
Reputation: 595
ex2cCalculator.c
is a probably a source file, what you need there is the name of the executable (ex2cCalculator
, a.out
whatever)
There are also excess elements in the array initializer. It should be char *a[3] = { "calculator", "2+1", NULL };
Upvotes: 2