I'm trying to write a program using named pipes, and I'm having trouble opening it. In another program I call this line:

mkfifo("./fife", 0777);

So my named pipe exists and I see it in my list of files. Then I run the program I included below, but I can not get past the open call. Any help would be appreciated for I can not find a lot of resources on this subject.

#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <iostream>

#define MSGSIZE 14

void main() {
  char *message = "Hello, world!";

  int fd;
  fd = open("fife", O_WRONLY);
 // Can not get past this point!

  cout << "fd: " << fd << endl;

  if (write(fd, message, MSGSIZE) < 0)
    cout << "error writing" << endl;

10 Years
Discussion Span
Last Post by Salem

I found out the problem. It waits because it wants another program to handle the other end of the pipe.

I fixed my codes up and I wrote a script like this to fix the problem:

echo "Running clients..."
./client &
./client &

echo "Running server..."
# The & runs the program in the background, so you can run another program, playing client and server in the same console

a) you're too late - by at least a year, check the dates.
b) try programming something for yourself.
c) start your own thread when you've got something to show.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.