一、实验目的
1、了解有名管道通信的原理。
2、掌握有名管道的创建及使用方法。
二、实验内容
1、使用mkfifo函数创建一个有名管道。以阻塞方式打开管道,将磁盘文件test1的内容都读取到管道中。
2、以阻塞方式打开管道,将管道中的数据写入文件test2,从而在test1与test2之间完成拷贝文件的功能。
3、编译并分别在两个终端里运行读端和写端程序,查看结果。
三、实验源程序及结果截图
Fifowrite.c文件:
#include <unistd.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <limits.h>
#include<errno.h>
#include <string.h>
int main(){
const char *fifo_name="my_fifo";
const int open_mode=O_WRONLY;
const char *open_mode_name="O_WRONLY";
if(access(fifo_name,F_OK)==-1){
int res

本文介绍了如何通过C语言实现有名管道,演示了从文件test1读取内容写入管道,然后在另一终端通过管道将数据写入test2的过程。实验中还讨论了创建管道、权限设置和打开方式对程序的影响。
最低0.47元/天 解锁文章
4038

被折叠的 条评论
为什么被折叠?



