C Program to show an example of fork and exec System Calls
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
int main()
{
pid_t pid;
char *args[]={"/bin/ls","-l",0};
printf("Parent Process PID :%d",getpid());
pid=fork();
if(pid==0)
{
printf("\nChild process PID :%d and Parent process is: %d\n",getpid(),getppid());
}
else
{
wait();
execv("/bin/ls",args);
exit(0);
}
}