-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtick.c
More file actions
36 lines (30 loc) · 622 Bytes
/
tick.c
File metadata and controls
36 lines (30 loc) · 622 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
/* FIFO read "tick"
* October 28, 2021 */
/* Use with speak.c */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#define FIFO_NAME "pipe.fifo"
int main(void) {
char s[300];
int num, fd;
mknod(FIFO_NAME, S_IFIFO | 0666, 0);
printf("Waiting for writers\n");
fd = open(FIFO_NAME, O_RDONLY);
printf("Got a writer\n");
do {
if ((num = read(fd, s, 300)) == -1)
perror("read");
else {
s[num] = '\0';
printf("Tick: Read %d bytes: %s", num, s);
}
} while (num > 1);
putchar('\n');
close(fd);
return 0;
}