Preview:
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <fcntl.h>

#include <unistd.h>

#include <sys/types.h>

#include <sys/stat.h>

#define FIFO_NAME "myfifo"

int main() {

    int fd;

    char *message = "Hello from writer process!";

    

    // Create the FIFO if it does not exist

    if (mkfifo(FIFO_NAME, 0666) == -1) {

        perror("mkfifo");

        exit(EXIT_FAILURE);

    }

    // Open the FIFO for writing

    fd = open(FIFO_NAME, O_WRONLY);

    if (fd == -1) {

        perror("open");

        exit(EXIT_FAILURE);

    }

    // Write the message to the FIFO

    if (write(fd, message, strlen(message) + 1) == -1) {

        perror("write");

        close(fd);

        exit(EXIT_FAILURE);

    }

    printf("Writer: Wrote message to FIFO.\n");

    

    // Close the FIFO

    close(fd);

    return 0;

}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter