1,思维导图
2,创建子父
#include<myhead.h>
int main(int argc, const char *argv[])
{
pid_t pid;
pid=fork();
if(pid>0)
{
int fp3=open("./3.txt",O_RDONLY);
int fp4=open("./4.txt",O_CREAT|O_TRUNC|O_WRONLY,0664);
char str1[5];
int count1=0;
while(count1=read(fp3,str1,sizeof(str1)))
{
if(write(fp4,str1,count1)!=count1)
{
break;
}
}
close(fp3);
close(fp4);
}
else if(pid==0)
{
int fp1=open("./1.txt",O_RDONLY);
int fp2=open("./2.txt",O_CREAT|O_TRUNC|O_WRONLY,0664);
char str2[5];
int count2=0;
while(count2=read(fp1,str2,sizeof(str2)))
{
if(write(fp2,str2,count2)!=count2)
{
break;
}
}
close(fp1);
close(fp2);
}
return 0;
}
进程,子进程实现1.txt复制2.txt,父进程实现3.txt复制4.txt