在 C 中打开 FIFO 时遇到问题
我在 C 中打开 FIFO 时遇到了麻烦。首先,我使用 mkfifo() 函数创建它们,权限为:0777,当我尝试打开它们时,它仅成功打开第一个 FIFO,然后进程将卡在打开第二个 FIFO,这是我的代码:
fd1 = open("FIFO1_PATH", O_WRONLY );
fd2 = open("FIFO2_PATH", O_WRONLY );
这不会被执行,但是一旦我注释第二行,它就会执行!每个进程打开 FIFO 的数量是否有限制?我不知道为什么会发生这种情况..我只是花了 3 个小时试图找出问题所在,但没有任何结果:(
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 :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚做对了:)
我必须让打开的进程等待,直到其他进程打开 FIFO 进行读取(这将是阻塞读取)。通过在写入进程上进行睡眠,我将确保其他进程将打开阅读..
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 ..
回答有关限制的问题 - Linux 中默认进程的文件描述符为 1024 个。您的问题可能是没有打开第二个 FIFO 进行读取,而没有打开第二个 FIFO 进行写入块。
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.