FIFO server program

↘锁芯ラ 提交于 2019-12-25 10:00:11

问题


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);

回答1:


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);


来源:https://stackoverflow.com/questions/8045626/fifo-server-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!