after fork is invoked you can exec the same child process to execute some other program so that I can easily understand the purpose of exec.
if we can create another process to excute someother program through exec ...
why do we need fork sysstem call which can only create a process but cant execute someother program?
You can include exec after fork system call and execute someother program so that its easier for me to understand exec.
If we can create another and process to execute someother program through exec system call then why do we need fork call which can only create a process and cant be made to execute another program?
fork() creates a child process,, pretty much identical to the parent. (As you've seen above.)
exec() replaces the current process with the named executable file. The variants of exec indicate how the parameters. l means the program args are passed as a list, v means the program args are passed as an array, e means an environment can be passed, and p means the program passed in may be a script and needs to be interpretted.
So execvp() expects the args to be passed in an array, and the command can be a script, the current environment is used.
execle() expects the args to be passed as a list, and the environment to be specified.
I accept this is probably your homework, but here's a simple shell thing that just executes stuff. It demonstrates how to run one program from another.