#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main(){
pid_t pid;
pid = fork();
if(pid<0){
fprintf(stderr, "fork failed");
return 1; }
else if(pid == 0){
execlp("bin/ls", "ls", NULL);}
else{
wait(NULL);
printf("child complete\n");
}
return 0;
}
Here as far as I could understand, a child process is created and since its pid returned by fork is "0", it enters the block containing execlp and executes it, and then the parent waits till the child exits and then prints "child complete". Please correct me if I'm wrong. But I didnt understand how execlp() works here. Can someone explain this?