#include #include #include #include #include // this process says hi to another process // and the other process says hi back int main() { int w_fd = open("./fifo_a2b", O_WRONLY); int r_fd = open("./fifo_b2a", O_RDONLY); printf("I am process with PID %d\n", getpid()); char *msg = malloc(sizeof(char) * 100); memset(msg, 0, sizeof(char) * 100); sprintf(msg, "Hello, my name is %d", getpid()); int size = strlen(msg); if(-1 == write(w_fd, &size, sizeof(int))) { perror("Error sending message length"); } if(-1 == write(w_fd, msg, size * sizeof(char))) { perror("Error saying hi"); } free(msg); size = 0; if(-1 == read(r_fd, &size, sizeof(int))) { perror("Error reading message length"); } if(size > 0) { msg = malloc(sizeof(char) * (size + 1)); if(-1 == read(r_fd, msg, sizeof(char) * size)) { perror("Error reading message"); } msg[size] = 0; printf("Received message: %s\n", msg); free(msg); } close(r_fd); close(w_fd); return 0; }