作者:huai | 来源:互联网 | 2023-05-18 21:53
CurrentlyworkingonanassignmentinwhichweareworkingwithnamedpipesinC.Ineedtobeable
Currently working on an assignment in which we are working with named pipes in C. I need to be able to read and write to a pipe. Here's where I am confused. I know there are kind of two different types of pipes (or different ways to make them). I know that there is a pipe function that you can read and write to an anonymous pipe. In our assignment writeup, I learned that you use mkfifo to create a named pipe in the directory. However, it also stated that you can then use that pipe like a normal file but when I try to use it as such, it just hangs. Here's my code:
目前正在处理我们在C中使用命名管道的分配。我需要能够读取和写入管道。这是我困惑的地方。我知道有两种不同类型的管道(或不同的管道方式)。我知道有一个管道功能,你可以读取和写入匿名管道。在我们的作业编写中,我了解到你使用mkfifo在目录中创建一个命名管道。但是,它还声明您可以像普通文件一样使用该管道但是当我尝试使用它时,它只是挂起。这是我的代码:
#include
int main(int argc, char * argv[]){
FILE *fp;
fp = fopen("pipe", "r");
char c = 'o';
fputc(c, fp);
fclose(fp);
}
So are pipes not actually usable in this way? Any help is greatly appreciated! Thanks
管道实际上是不是以这种方式可用?任何帮助是极大的赞赏!谢谢
1 个解决方案