#include<head.h>
int main(int argc, char const *argv[])
{
int fd=-1;
if((fd=open("./0731.txt",O_WRONLY|O_CREAT|O_TRUNC,0664))==-1)
{
perror("open error");
return -1;
}
char arr[20]="aaaaazzzzz";
// printf("请输入一段字符:");
// fgets(arr,sizeof(arr),stdin);
write(fd,arr,sizeof(arr));
close(fd);
int fb=-1;
if((fb=open("./07311.txt",O_WRONLY|O_CREAT|O_TRUNC,0664))==-1)
{
perror("open error");
return -1;
}
if((fd=open("./0731.txt",O_RDONLY))==-1)
{
perror("open error");
return -1;
}
char brr[20]="";
read(fd,brr,sizeof(brr));
pid_t pid=-1;
pid=fork();
if(pid>0)
{
write(fb,brr,sizeof(brr)/2);
sleep(1);
}else if(pid==0)
{
write(fb,brr+sizeof(brr)/2,sizeof(brr)/2);
exit(0);
}else
{
perror("fork error");
return -1;
}
close(fd);
close(fb);
wait(NULL);
while(1);
return 0;
}