利用命名管道复制文件
2013-04-25 22:56
447 查看
1. 定义头文件apue.h
#ifndef _APUE_H_
#define _APUE_H_
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <assert.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>
#include <signal.h>
#include <sys/time.h>
void err_exit(char *m){
perror(m);
exit(EXIT_FAILURE);
}
#endif /* _APUE_H_ */
2. fifor.c, 把文件Makefile的内容读取到管道tp中
#include "../apue.h"
int main(void){
mkfifo("tp", 0644);
int infd;
infd=open("Makefile", O_RDONLY);
if(infd==-1)
err_exit("open error");
int outfd;
outfd=open("tp", O_WRONLY);
if(outfd==-1)
err_exit("open error");
char buf[1024];
int n;
n=read(infd, buf, 1024);
write(outfd, buf, n);
return 0;
}
3.02fifow.c, 从管道tp中读取数据并写入文件Makefile2
#include "../apue.h"
int main(void){
int fd;
fd=open("tp", O_RDONLY);
if (fd==-1)
err_exit("open error");
int infd;
infd=open("Makefile2", O_WRONLY|O_CREAT, 0644);
if (infd==-1)
err_exit("open error");
char buf[1024];
int n;
while ((n=read(fd, buf, 1024))>0){
write(infd, buf, n);
}
return 0;
}
#ifndef _APUE_H_
#define _APUE_H_
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <assert.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>
#include <signal.h>
#include <sys/time.h>
void err_exit(char *m){
perror(m);
exit(EXIT_FAILURE);
}
#endif /* _APUE_H_ */
2. fifor.c, 把文件Makefile的内容读取到管道tp中
#include "../apue.h"
int main(void){
mkfifo("tp", 0644);
int infd;
infd=open("Makefile", O_RDONLY);
if(infd==-1)
err_exit("open error");
int outfd;
outfd=open("tp", O_WRONLY);
if(outfd==-1)
err_exit("open error");
char buf[1024];
int n;
n=read(infd, buf, 1024);
write(outfd, buf, n);
return 0;
}
3.02fifow.c, 从管道tp中读取数据并写入文件Makefile2
#include "../apue.h"
int main(void){
int fd;
fd=open("tp", O_RDONLY);
if (fd==-1)
err_exit("open error");
int infd;
infd=open("Makefile2", O_WRONLY|O_CREAT, 0644);
if (infd==-1)
err_exit("open error");
char buf[1024];
int n;
while ((n=read(fd, buf, 1024))>0){
write(infd, buf, n);
}
return 0;
}
相关文章推荐
- 利用命名管道(Named Pipe)向Flash Player模拟Flash媒体文件
- 利用VC++实现对文件的复制、删除、重命名
- Linux 批量复制并重命名 和 批量复制文件到多个文件夹
- Windows Server 利用xcopy在复制文件或文件夹保留权限
- Java IO学习【13】利用字节流复制文件的4种方法详解
- python 学习记录(11)-文件处理/读取文件/文件写入内容/文件删除/文件复制/文件重命名/后缀名/内容查找与替换/文件比较/ 配置文件访问/目录创建与删除/遍历目录/定向输出
- 进程间通信(三):利用命名管道
- 文件(夹)复制、删除、重命名
- linux 下文件重命名/移动/复制命令(转)
- 使用批处理批量复制文件并重命名
- DOS教学帖:复制不同文件夹下的同名文件至同一文件夹下并自动重命名的批处理
- 利用管道命名锁,实现进程间名称的不同
- IO流——利用字节流缓冲区复制MP3文件
- C#实现的文件操作封装类完整实例【删除,移动,复制,重命名】
- C++ 文件的复制、删除、重命名
- java实现FTP远程文件移动(重命名、复制、拷贝)
- 利用Windows 计划任务定时将本地文件复制到共享文件夹
- 管道方式实现文件复制
- 利用xcopy在复制文件或文件夹的时候保留其权限
- 分享一个自己利用学的IO流操作封装了一个小工具进行文件复制剪切和删除功能