// This library contains the open() function. #include // This library contains the printf() function. #include // This library contains the read() function. #include int main() { // Buffer size const int B_SIZE = 100; // Initialization of the buffer. char buf[B_SIZE]; // Name of the pipe char pathname[] = "named_pipe"; // Opens the named pipe with read and write privileges. int fd = open(pathname, O_RDWR); // Returns early if the named pipe is inaccessible if (fd == -1) { printf("Error opening named pipe.\n"); return -1; } // Reads the content in the pipe to the buffer. int status = read(fd, buf, B_SIZE); if (status == -1) { // Prints if there are errors encountered in reading the contents of the pipe. printf("Error reading pipe.\n"); } else { // Prints the message read from the pipe. printf("Message read from named pipe is: %s\n", buf); } }