Finishing bootstrap program.
[wsti_so.git] / src / process3.c
1 #include <stdio.h>
2
3 /* open/read/write/close */
4 #include <fcntl.h>
5
6 /**
7  * Program grabs data (calculated number of characters) from process2 and prints
8  * grabbed data to the standard output.
9  */
10 int main(void) {
11         /** Named pipe used to communicate with process2 */
12         char * read_pipe = "/tmp/process2pipe";
13
14         /** Descriptor of input pipe */
15         int read_descriptor;
16
17         /** Buffer used for storing data from input pipe */
18         int buffer = 0;
19         
20         /** Stores number of bytes read from input pipe in current iteration */
21         ssize_t count = 0;
22
23         /* Reading from process2 */
24         read_descriptor = open(read_pipe, O_RDONLY);
25
26         fprintf(stderr, "[%s] Init!\n", "process3");
27
28         while(1) {
29                 /* Read data from input pipe */
30                 count = read(read_descriptor, &buffer, sizeof(int));
31
32                 fprintf(stderr, "[%s] Fetched: %d bytes\n", "process3", count);
33
34                 if (count > 0) {
35                         fprintf(stderr, "[%s] Process2 send: %d\n", "process3", buffer);
36                 }
37                 else {
38                         break;
39                 }
40         }
41
42         close(read_descriptor);
43
44         return 0;
45 }