3 /* open/read/write/close */
6 /** If buffer is too small to hold entire string, it is incremented by this value */
10 * Program grabs data from process1, calculates number of characters in each line
11 * and pass the value to process3.
14 /** Named pipe used to communicate with process1 */
15 char * read_pipe = "/tmp/process1pipe";
17 /** Named pipe used to communicate with process3 */
18 char * write_pipe = "/tmp/process2pipe";
23 char buffer[BUFFER_STEP];
28 /* Reading from process1 */
29 read_descriptor = open(read_pipe, O_RDONLY);
31 /* Writing to process2 */
32 mkfifo(write_pipe, 0666);
33 write_descriptor = open(write_pipe, O_WRONLY);
35 int number_of_characters = 0;
38 /* Read data from input pipe */
39 count = read(read_descriptor, buffer, BUFFER_STEP);
41 fprintf(stderr, "[%s] Fetched: %d bytes\n", "process2", count);
44 for (i = 0; i < count; i++, number_of_characters++) {
45 if (buffer[i] == '\n') {
46 fprintf(stderr, "[%s] Calculated: %d characters. Sending...\n", "process2", number_of_characters);
47 write(write_descriptor, &number_of_characters, sizeof(number_of_characters));
48 write(write_descriptor, '\n', 1);
49 number_of_characters = 0;
58 close(read_descriptor);
59 close(write_descriptor);
60 unlink(write_descriptor);