writer.c

#include <stdio.h>

#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#include "utils.h"

#define FIFO_PATH "/tmp/ex-fifo"

int main(int argc, char *argv[])
{
    char buffer[100];
    int n;
    int fd = open(FIFO_PATH, O_WRONLY);
    exit_if(fd == -1, FIFO_PATH);
    printf("file %s is open for write\n", FIFO_PATH);
    n = snprintf(buffer, sizeof(buffer),
            "I'm the child %d, of %d\n", getpid(), getppid());
    write(fd, buffer, n);
    printf("end of writer\n");
    return 0;
}