I know that exec() functions dont come back unless they fail.
that is why i created a child process so to parent process waits for the child.
But in my case the program does not come back. what am I missing?
Code:
/*
* main.c
*/
#include "execute.h"
main(){
char *argument = "barbara.pgm";
printf("executing invert:...\n");
execute(2,argument);
printf("ended.\n");
}
and the execute.h
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static char *program[8] = {
"./avgFilter",
"./binarize",
"./invert",
"", "", "", ""};
void execute(short progNumber, char * fileName){
int pid;
int status;
/*
* Get a child process
*/
if((pid = fork()) < 0){
perror("fork: ");
exit(EXIT_FAILURE);
}
/*
* The child executes the program
*/
if(pid == 0){
execl(program[progNumber],program[progNumber], fileName, (char *)0);
perror("execl");
exit(EXIT_FAILURE);
}
/*
* The parent process just waits
*/
if (pid >= 1) {
wait(&status);
}
exit(EXIT_SUCCESS);
}