Working communication using pipes.
[wsti_so.git] / src / process3.c
diff --git a/src/process3.c b/src/process3.c
new file mode 100644 (file)
index 0000000..d5be26a
--- /dev/null
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* open/read/write/close */
+#include <fcntl.h>
+
+/** If buffer is too small to hold entire string, it is incremented by this value */
+#define BUFFER_STEP 16
+
+/**
+ * Program grabs data from process1, calculates number of characters in each line
+ * and pass the value to process3.
+ */
+int main(void) {
+       /** Named pipe used to communicate with process1 */
+       char * read_pipe = "/tmp/process2pipe";
+
+       int read_descriptor;
+       
+       int buffer = 0;
+       
+       int i = 0;
+       ssize_t count = 0;
+
+       /* Reading from process2 */
+       read_descriptor = open(read_pipe, O_RDONLY);
+
+       int number_of_characters = 0;
+       
+       while(1) {
+               /* Read data from input pipe */
+               count = read(read_descriptor, &buffer, sizeof(int));
+
+               fprintf(stderr, "[%s] Fetched: %d bytes\n", "process3", count);
+
+               if (count > 0) {
+                       fprintf(stderr, "[%s] Process2 send: %d\n", "process3", buffer);
+               }
+               else {
+                       break;
+               }
+       }
+
+       close(read_descriptor);
+
+       return 0;
+}
\ No newline at end of file