我正在尝试使用mknod()命令创建一个名为管道的FIFO:
int main() {
char* file="pipe.txt";
int state;
state = mknod(file, S_IFIFO & 0777, 0);
printf("%d",state);
return 0;
}但该文件不是在我的当前目录中创建的。我试着用ls -l把它列出来。状态返回-1。
我在这里和其他网站上都发现了类似的问题,我尝试过大多数人建议的解决方案:
int main() {
char* file="pipe.txt";
int state;
unlink(file);
state = mknod(file, S_IFIFO & 0777, 0);
printf("%d",state);
return 0;
}但是,这并没有什么区别,而且错误仍然存在。我在这里做错了什么吗?还是有某种系统干预导致了这个问题?
救命..。提前感谢
发布于 2015-07-16 16:51:17
您正在使用&来设置文件类型,而不是|。从医生那里:
路径的文件类型或被编辑为模式参数,应用程序将选择下列符号常量之一.
试试这个:
state = mknod(file, S_IFIFO | 0777, 0);因为这起作用是:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main() {
char* file="pipe.txt";
int state;
unlink(file);
state = mknod(file, S_IFIFO | 0777, 0);
printf("state %d\n", state);
return 0;
}汇编:
gcc -o fifo fifo.c运行它:
$ strace -e trace=mknod ./fifo
mknod("pipe.txt", S_IFIFO|0777) = 0
state 0
+++ exited with 0 +++见结果:
$ ls -l pipe.txt
prwxrwxr-x. 1 lars lars 0 Jul 16 12:54 pipe.txthttps://stackoverflow.com/questions/31459997
复制相似问题