Aim: Programs related to interposes communication using pipes.
(RHS) Theory: Program You know
a) Sender.c
b) Receiver.c
(LHS) Output:
#include"stdio.h"
#include"sys/stat.h"
#include"fcntl.h"
int main()
{
char data[100];
int fd=0, len=0, i=1;
fd=open("Datapipe",O_WRONLY);
if(fd==-1)
{
printf("\n Receiver process has not created yet");
return 1;
}
while(1)
{
len=read(0,data,100);
if(len<=1)
{
break;
}
write(fd,data,len);
}
close(fd);
printf("\n");
return 0;
}
#include"sys/stat.h"
#include"fcntl.h"
int main()
{
char data[100];
int fd=0, len=0, i=1;
unlink("Datapipe");
mkfifo("Datapipe",0660);
fd=open("Datapipe",O_RDONLY);
if(fd==-1)
{
printf("\n Error creating pipe");
return 1;
}
while(1)
{
len=read(fd,data,100);
if(len<=0)
{
break;
}
data[len]='\0';
printf("\nString %d : %s",1,data);
i++;
}
close(fd);
unlink("Datapipe");
printf("\n");
return 0;
}
(RHS) Theory: Program You know
a) Sender.c
b) Receiver.c
(LHS) Output:
//Sender.c File
#include"sys/stat.h"
#include"fcntl.h"
int main()
{
char data[100];
int fd=0, len=0, i=1;
fd=open("Datapipe",O_WRONLY);
if(fd==-1)
{
printf("\n Receiver process has not created yet");
return 1;
}
while(1)
{
len=read(0,data,100);
if(len<=1)
{
break;
}
write(fd,data,len);
}
close(fd);
printf("\n");
return 0;
}
On Next Page
// Receiver.c file
#include"stdio.h"#include"sys/stat.h"
#include"fcntl.h"
int main()
{
char data[100];
int fd=0, len=0, i=1;
unlink("Datapipe");
mkfifo("Datapipe",0660);
fd=open("Datapipe",O_RDONLY);
if(fd==-1)
{
printf("\n Error creating pipe");
return 1;
}
while(1)
{
len=read(fd,data,100);
if(len<=0)
{
break;
}
data[len]='\0';
printf("\nString %d : %s",1,data);
i++;
}
close(fd);
unlink("Datapipe");
printf("\n");
return 0;
}
LHS:
AIM:………………………………
Compile:
Termianl 1:
gcc sender.c –o
sender.out
gcc receiver.c –o
receiver.out
Run:
Terminal 1:
./receiver.out
Terminal 2:
./sender.out
Now take screen shots after run the program in proper way
No comments:
Post a Comment