Having a trouble with opening FIFO in C

巧了我就是萌 提交于 2019-12-10 15:38:59

问题


I'm having a trouble in opening FIFOs in C.. first I created them using mkfifo() function with permission : 0777, and when I tried to open them, it succeeded in opening the first FIFO only, then the process will stuck in opening the second FIFO, and this is my code :

fd1 = open("FIFO1_PATH", O_WRONLY );
fd2 = open("FIFO2_PATH", O_WRONLY );

This will not be executed, but once I comment the second line, it executes ! Is there a limit for the number of opening FIFOs per process ? I don't know why is this happening.. I just spent 3 Hours trying to figure out what the problem is, but without any results :(


回答1:


To answer you question about limits - default in Linux is 1024 file descriptors for a process. Your problem is probably not opening the second FIFO for reading so open for writing blocks.




回答2:


I just got it right :)

I have to let the opening process wait until some other process opens the FIFO for reading (and it will be a blocked reading).. by doing sleep on the writing process I will ensure that the other process will opens for reading ..



来源:https://stackoverflow.com/questions/4561925/having-a-trouble-with-opening-fifo-in-c

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