-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipe.c
More file actions
41 lines (32 loc) · 822 Bytes
/
pipe.c
File metadata and controls
41 lines (32 loc) · 822 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
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
void main()
{
int id, pipefd[2];
char buffer[20];
pipe(pipefd);
id = fork();
if(id < 0)
{ printf("Process cannot be created!!!\n");
exit(-1);
}
if(id == 0)
{ printf("Enter END-1 message : \n");
scanf("%s", buffer);
write(pipefd[1], buffer, 20);
sleep(1);
lseek(pipefd[0], 0 , SEEK_SET);
read(pipefd[0], buffer, 20);
printf("END-1 reads message : %s\n", buffer);
}
else
{ lseek(pipefd[0], 0 , SEEK_SET);
read(pipefd[0], buffer, 20);
printf("END-2 reads message : %s\n", buffer);
printf("Enter END-2 message : \n");
scanf("%s", buffer);
write(pipefd[1], buffer, 20);
sleep(1);
}
}