1
我已经创建了fifo,尝试写入它:echo "text" > myfifo
并用我的程序读取它。 但是当我写信给fifo什么都没有显示。在Linux下编程 - FIFO
我已经尝试了很多选择,关闭和NON_BLOCK
模式等,但似乎没有任何帮助。
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
int main (int argc, char **argv)
{
int c;
int tab[argc/2];//decriptors
int i=0;
while ((c = getopt (argc, argv, "f:")) != -1) {
switch (c) {
case 'f':
if (tab[i] = open(optarg, O_RDONLY| O_NONBLOCK) == -1) {
perror(optarg);
abort();
}
//dup(tab[i]);
//printf(":::::%d==== %s\n",555,optarg);
i++;
break;
default:
abort();
}
}
printf("----------------------\n");
char cTab[10];
int charsRead;
for(int j=0;j<=i;j++)
{
charsRead = read(tab[j], cTab, 10);
printf(" ==%d+++%s\n",tab[j],cTab);
//write(tab[j],cTab,10);
}
for(int j=0;j<i;j++)
{
close(tab[j]);
}
您使用了'C++'标签,但是这看起来是直接的C代码。 –
反正它不起作用... – Knight
你到底在干什么?怎么了?你预期会发生什么? – melpomene