-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path020.c
More file actions
53 lines (50 loc) · 1.65 KB
/
020.c
File metadata and controls
53 lines (50 loc) · 1.65 KB
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
45
46
47
48
49
50
51
52
53
/*
..........................................................................................................................................
Name : 030.c
Author : SHRUTI VERMA
Description : Write two programs so that both can communicate by FIFO -Use one way communication.
Date : 16 Sep 2025
..........................................................................................................................................
*/
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<sys/types.h>
#include<fcntl.h>
#include<sys/stat.h>
int main() {
int choice = 0;
int fd = -1;
mkfifo("myFifo2", 0666);
printf("1. Writer process\n2. Reader process\nEnter your choice : ");
scanf("%d", &choice);
if(choice == 1) {
fd = open("myFifo2", O_WRONLY);
char msg[30];
scanf(" %[^\n]", msg);
write(fd, msg, sizeof(msg));
close(fd);
} else {
fd = open("myFifo2", O_RDONLY);
char buf[100];
read(fd, buf, sizeof(buf));
printf("Data from writer : %s\n", buf);
close(fd);
}
}
/*------------------------------------------------OUTPUT---------------------------------------------
terminal 1
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ gcc 020.c -o 020.out
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ ./020.out
1. Writer process
2. Reader process
Enter your choice : 1
hi guys
terminal 2
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ gcc 020.c -o ./020.out
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ ./020.out
1. Writer process
2. Reader process
Enter your choice : 2
Data from writer : hi guys
*/