Named Pipe (FIFO)

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2005
Posts: 78
Reputation: nanodano is an unknown quantity at this point 
Solved Threads: 2
nanodano's Avatar
nanodano nanodano is offline Offline
Junior Poster in Training

Named Pipe (FIFO)

 
0
  #1
Feb 13th, 2007
Hi,
I'm trying to write a program using named pipes, and I'm having trouble opening it. In another program I call this line:
  1. 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.

  1. #include <sys/types.h>
  2. #include <sys/wait.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include <stdlib.h>
  6. #include <sys/stat.h>
  7. #include <iostream>
  8.  
  9. #define MSGSIZE 14
  10.  
  11. void main() {
  12. char *message = "Hello, world!";
  13.  
  14. int fd;
  15. fd = open("fife", O_WRONLY);
  16. // Can not get past this point!
  17.  
  18. cout << "fd: " << fd << endl;
  19.  
  20. if (write(fd, message, MSGSIZE) < 0)
  21. cout << "error writing" << endl;
  22.  
  23. close(fd);
  24. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Named Pipe (FIFO)

 
0
  #2
Feb 13th, 2007
Look at the errno which open sets, when it returns with a failure?
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 78
Reputation: nanodano is an unknown quantity at this point 
Solved Threads: 2
nanodano's Avatar
nanodano nanodano is offline Offline
Junior Poster in Training

Re: Named Pipe (FIFO)

 
0
  #3
Feb 14th, 2007
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:

  1. #!/bin/bash
  2. echo "Running clients..."
  3. ./client &
  4. ./client &
  5.  
  6. echo "Running server..."
  7. ./server
  8. # The & runs the program in the background, so you can run another program, playing client and server in the same console
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 1
Reputation: mustihi is an unknown quantity at this point 
Solved Threads: 0
mustihi mustihi is offline Offline
Newbie Poster

Re: Named Pipe (FIFO)

 
0
  #4
May 21st, 2008
can you post the client program (reading program) too?
Last edited by mustihi; May 21st, 2008 at 8:58 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Named Pipe (FIFO)

 
0
  #5
May 21st, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC