EmbLogic's Blog

Execl file replacement

Sir I have made two files in home/vivek/process directory named fork.c and add.c and I had made one child process and then call execl function by giving its path/file name then file name and then NULL argument. But it is not executing execl function and gave output as it is giving in child and parent. I have attached my code blelow

# include
# include
# include
#include
#include

int main()
{
pid_t pid;
int n,k;
pid=fork();
if(pid>0)
{
wait(&k);
WIFEXITED(k);
n=2;
printf(“\nmy argument is=%d\n”,WEXITSTATUS(k));
printf(“\ni am a parent and my id=%d\n”,getpid());
}
else
{
execl(“./add.c”,”add”,NULL);
n=4;
printf(“\ni am a child and my id=%d\n”,getpid());
}
return(n);
}

#include

int main()
{
int a,b,sum;
a=3;
b=6;
printf(“\nenter value of a=”);
scanf(“%d”,&a);
printf(“\nenter value of b=”);
scanf(“%d”,&b);
printf(“\nfinal result”);
sum=a+b;
printf(“\nsum=%d\n”,sum);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>