3 #include <stdio.h>
4 #include <errno.h>
5 #include <unistd.h>
6
7 /* main --- создание канала, запись в него и чтение из него. */
8
9 int main(int argc, char **argv)
10 {
11 static const char mesg[] = "Don't Panic!"; /* известное сообщение */
12 char buf[BUFSIZ];
13 ssize_t rcount, wcount;
14 int pipefd[2];
15 size_t l;
16
17 if (pipe(pipefd) < 0) {
18 fprintf(stderr, "%s: pipe failed: %s\n", argv[0],
19 strerror(errno));
20 exit(1);
21 }
22
23 printf("Read end = fd %d, write end = fd %d\n",
24 pipefd[0], pipefd[1]);
25
26 l = strlen(mesg);
27 if ((wcount = write(pipefd[1], mesg, 1)) != 1) {
28 fprintf(stderr, "%s: write failed: %s\n", argv[0],
29 strerror(errno));
30 exit(1);
31 }
32