第一题
#include <myhead.h>
int main(int argc, const char *argv[])
{
pid_t ID;
ID = fork();
int fd1 = open("./1.txt",O_RDWR);
if(fd1==-1)
{
perror("open");
return -1;
}
int fd2 = open("./2.txt",O_CREAT|O_RDWR,0664);
if(fd2==-1)
{
perror("open");
return -1;
}
int fd3 = open("./3.txt",O_RDWR);
if(fd3==-1)
{
perror("open");
return -1;
}
int fd4 = open("./4.txt",O_CREAT|O_RDWR,0664);
if(fd4==-1)
{
perror("open");
return -1;
}
if(ID>0)
{
char buf[100];
int len = read(fd1,buf,sizeof(buf));
write(fd2,buf,len);
}
else if(ID==0)
{
char buf[100];
int len = read(fd3,buf,sizeof(buf));
write(fd4,buf,len);
}
else
{
perror("fork");
return -1;
}
return 0;
}
ubuntu@ubuntu:~