Files
OS/lab6/pipe_read.c
2025-04-23 23:07:22 +08:00

24 lines
431 B
C

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main() {
int fd = open("/dev/wendy_out", O_RDONLY);
if (fd < 0) {
printf("Error open pipe");
return 1;
}
char buf[128];
ssize_t n = read(fd, buf, sizeof(buf) - 1);
if (n < 0) {
printf("Error read pipe");
return 1;
}
buf[n] = '\0';
printf("Reader received: %s", buf);
close(fd);
return 0;
}