linux ------- 多进程实现大文件拷贝

本文探讨如何利用Linux的fork和mmap技术,通过创建子进程实现多进程并行拷贝大文件,以提高拷贝效率。在操作中,确保文件打开权限与mmap映射区权限匹配,防止段错误。
摘要由CSDN通过智能技术生成

多进程可以加快大文拷贝的速率,利用fork,创建子进程进行多个进程同时处理拷贝任务。

/*************************************************************************
	> File Name: project.c
	> Author: xuchen_allen
	> Mail: xuchen_allen@163.com 
	> Created Time: 2019年02月03日 星期日 10时35分47秒
 ************************************************************************/

#include<stdio.h>
#include<sys/types.h>
#include<sys/mman.h>
#include<unistd.h>
#include<fcntl.h>
#include<stdlib.h>
#include<sys/stat.h>
#include<sys/wait.h>
#include<string.h>
int main(int argc,char*argv[])
{
	struct stat infor;
	int fd,fd_copy;

	//创建一个接受拷问数据的文件:
	fd_copy=open("copy_test",O_RDWR|O_CREAT|O_TRUNC,0644);
    if(fd_copy<0){
		perror("open copy fail");
		exit(1);
	}
	if(argc<2){
		perror("worng");
		exit(1);
	}

	fd = open(argv[1],O_RDONLY);
	if(fd<0){
		perror("open fail"
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值