多进程思维导图
1> 思维导图
2> 使用父子进程完成两个文件的拷贝,父进程拷贝前一半,子进程拷贝后一半,两个进程同时进行(君子作业)
#include <myhead.h>
typedef struct sockaddr_in addr_in_t;
typedef struct sockaddr addr_t;
typedef struct sockaddr_un addr_un_t;
void zijincheng(int wfd,int rfd,int guang_biao){
lseek(wfd,guang_biao/2,SEEK_SET);
lseek(rfd,guang_biao/2,SEEK_SET);
char ch ;
for(int i=0;i<guang_biao/2;i++){
int res = read(rfd,&ch,1);
write(wfd,&ch,1);
//if()abreak;
}
exit(0);
}
int main(int argc, const char *argv[])
{
pid_t pid = fork();
int wfd = open(argv[2],O_WRONLY|O_CREAT|O_TRUNC,0664);
if(wfd==-1){
perror("write err:");
}
int rfd = open(argv[1],O_RDONLY);
if(rfd==-1){
perror("read err:");
}
int guang_biao = lseek(rfd,0,SEEK_END);
if(pid == 0){
zijincheng(wfd,rfd,guang_biao);
//exit(0);
}
char ch;
lseek(rfd,0,SEEK_SET);
for(int i=0;i<guang_biao/2;i++){
read(rfd,&ch,1);
write(wfd,&ch,1);
// if(res == 0)break;
}
wait(NULL);
return 0;
}