Thursday, 4 December 2014


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int child(int a,int b)
{
int sum;
sum=a+b;
sleep(5);
return(sum);
//parent(sum);
}
int parent(int sum)
{
int status;
wait(&status);
status>>=8;
//printf("sum=%d\n",sum);
//printf("sum=%d\n",sum);
}
main(int argc,char **argv)
{
int a,b,sum=0;
if(argc!=3)
printf("enter correct no of arguments\n");
a=atoi(argv[1]);
b=atoi(argv[2]);
if(fork())
printf("sum in parent process is=%d\n",parent(sum));
//printf("sum in parent process=%d\n",parent(sum));
else
printf("sum in child process=%d\n",child(a,b));
}
OutPut:
madan@madan-Lenovo-G570:~/madan/osconcepts$ cc ex43.c
madan@madan-Lenovo-G570:~/madan/osconcepts$ ./a.out 10 20
sum in child process=30
sum in parent process is=24