- WRITE A PROGRAM TO SHARE THE DATE BETWEEN PROCESSES USING FILES
#include<fcntl.h>
#include<stdio.h>
main()
{
int fp;
char chr=’A’;
int pid;
pid=fork();
if (pid==0)
{
fp=open(“baby”,O_WRONLY,0666);
printf(“ In child chr is %c\n”,chr);
chr=’B’;
write(fp,&chr,1);
printf(“ In child chr after change %c\n”,chr);
printf(“child exiting\n”);
close(fp);
}
else
{
wait((int*)0);
fp=open(“baby”,O_RDONLY);
read(fp,&chr,1);
printf(“ chr after parent reads is %c”,chr);
close(fp);
}
}
0 Comments