-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpp1.c
More file actions
44 lines (42 loc) · 761 Bytes
/
pp1.c
File metadata and controls
44 lines (42 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
int id,pd[2];
char buf[20];
pipe(pd);
id= fork();
if(id<0)
{
printf("Child can not be created");
exit(-1);
}
if(id==0)
{
printf("Enter server message : ");
scanf("%s",buf);
write(pd[1],buf,20);
sleep(1);
lseek(pd[0],0,SEEK_SET);
read(pd[0],buf,20);
printf("\nclient1 reads message : %s",buf);
lseek(pd[0],0,SEEK_SET);
read(pd[0],buf,20);
printf("\nclient2 reads message : %s",buf);
}
else
{
lseek(pd[0],0,SEEK_SET);
read(pd[0],buf,20);
printf("\nclient1 reads message : %s",buf);
printf("\nclient2 reads message : %s",buf);
printf("\nEnter client1 message : ");
scanf("%s",buf);
write(pd[1],buf,20);
sleep(1);
printf("\nEnter client2 message : ");
scanf("%s",buf);
write(pd[1],buf,20);
}
}