FIFO server program
Asked Answered
M

1

0

enter image description here

The above program i have typed in linux. It basically has to connect a client and server in separate terminals. But when i run them in the correct order, i.e

  1. Compile server -> run server
  2. Compile client - > run client

The terminals just dont do anything. It doesnt even print the "Trying to connect" part of the first printf statement. What is the mistake here?

EDIT

I checked for return value of mkfifo as @parapura rajkumar said. But Still it remains the same. Here is my changed code for server.

if(mkfifo("fifo1",0666)<0) {
  printf("Error");
}
if(mkfifo("fifo2",0666)<0) {
  printf("Error");
}
fflush(stdout);
Margiemargin answered 8/11, 2011 at 3:31 Comment(1)
Unless you are going to print more on one line using several printf calls, it is advised to end the printf with a new-line (\n) as that will flush the output so it's shown in the console. Then you don't need fflush.Dvina
E
2

You made deadlock. Server wait open("fifo1",O_RDONLY) and client wait open("fifo2",O_RDONLY).

Edit client.c:

int writefd = open("fifo1",O_WRONLY);
int readfd = open("fifo2",O_RDONLY);
Eggett answered 8/11, 2011 at 5:57 Comment(1)
To be more explicit, opening a fifo normally blocks until someone else opens it too so that they can be connected. (At least, by default -- it can be opened in non-blocking mode, though this makes things more complicated.)Aleutian

© 2022 - 2024 — McMap. All rights reserved.