5 /* open/read/write/close */
8 /** If buffer is too small to hold entire string, it is incremented by this value */
12 * Program grabs data from process1, calculates number of characters in each line
13 * and pass the value to process3.
16 /** Named pipe used to communicate with process1 */
17 char * read_pipe = "/tmp/process1pipe";
19 /** Named pipe used to communicate with process3 */
20 char * write_pipe = "/tmp/process2pipe";
25 char buffer[BUFFER_STEP];
30 /* Reading from process1 */
31 read_descriptor = open(read_pipe, O_RDONLY);
33 /* Writing to process2 */
34 mkfifo(write_pipe, 0666);
35 write_descriptor = open(write_pipe, O_WRONLY);
37 int number_of_characters = 0;
40 /* Read data from input pipe */
41 count = read(read_descriptor, buffer, BUFFER_STEP);
43 printf("fetched: %d bytes\n", count);
47 for (; j < count; j++, number_of_characters++) {
48 if (buffer[j] == '\n') {
49 fprintf(stderr, "Writting about: %d\n", number_of_characters);
50 write(write_descriptor, number_of_characters, sizeof(number_of_characters));
51 write(write_descriptor, '\n', 1);
52 number_of_characters = 0;
59 close(read_descriptor);
60 close(write_descriptor);
61 unlink(write_descriptor);