#include<sys/mman.h>
#include<fcntl.h>
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<string.h>
#define MAX_LEN 10485760 //10M 大于10M默认每个进程映射10M 修改应为4096的倍数
#define N 10 //进程拷贝 低于10M,选择此方式,默认开十个进程,可修改
int plen,pnum;
void sys_err(char *str)
{
perror(str);
exit(1);
}
int comFile(char *Fname)
{
int fd;
if(access(Fname, F_OK))
fd = open(Fname, O_CREAT|O_WRONLY,0664);
else
fd = open(Fname, O_RDONLY);
return fd;
}
int process_cp(int i, char *sfile, char *dfile)
{
char buf[1024] = {0};
int count;
int sd = open(sfile, O_RDONLY);
int dd = open(dfile, O_WRONLY);
if(sd < 0 || dd < 0)
sys_err("mmap_cp fileOpen");
lseek(sd, i*plen, SEEK_SET);
lseek(dd, i*plen, SEEK_SET);
if(i != N-1 )
{
多进程和mmap 实现copy的demo
最新推荐文章于 2023-10-16 12:50:46 发布