I have a question, I used the following program(fork() functions) to create a child process to overload another program using execl(). If I want to use echo command in the execl() functions or other kinds of exec() functions ,what should I do? I use following program, but it failed! the terminal gave me a warning:echo: cannot access hello world!: No such file or directory this is parent!
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main()
{ pid_t childpid;
childpid=fork();
if(childpid==-1){
perror("failed to fork");
return 1;
}
if(childpid==0)
{
execl("/bin/ls","echo","hello world!",NULL);
perror("child failed to exec");
return 1;
}
if(childpid!=wait(NULL)){
perror("parent failed to wait due to signal or error");
return 1;
}
sleep(5);
printf("this is parent!\n");
return 0;
}