-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path022.c
More file actions
42 lines (39 loc) · 1.36 KB
/
022.c
File metadata and controls
42 lines (39 loc) · 1.36 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
/*
..........................................................................................................................................
Name : 030.c
Author : SHRUTI VERMA
Description : Write a program to wait for data to be written into FIFO within 10 seconds, use select
system call with FIFO.
Date : 17 Sep 2025
..........................................................................................................................................
*/
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<sys/types.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/time.h>
#include<sys/select.h>
int main() {
fd_set rfds;
struct timeval tv;
tv.tv_sec=10;
int fd = open("myFifo", O_WRONLY);
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
if(!select(fd+1, &rfds, NULL, NULL, &tv)) {
printf("waiting for data to be written....\n");
} else {
printf("available for writing\n");
write(fd, "Hello there!", sizeof("Hello there!"));
printf("data written");
}
printf("doing other task\n");
}
/*-----------------------------------------OUTPUT-----------------------------------------------
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ gcc 022.c -o 022.out
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ ./022.out
waiting for data to be written....
doing other task
*/