#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<stdio.h>
#include<stdlib.h>
#include <unistd.h>
#include<string.h>
#include<unistd.h>
#include <sys/wait.h>
int main(int argc,char **argv)
{int fd1;
int fd2;
char *readBuf=NULL;
pid_t pid,pc;
int status;
if(argc!=3){
printf("程序错误!\n");
exit(-1);
}
fd1=open(argv[1],O_RDWR);
fd2=open(argv[2],O_RDWR|O_CREAT|O_TRUNC,0600);
pid=fork();
if(pid==0)
{
printf("我是子进程的ID=%d\n",getpid());
int size=lseek(fd1,0,SEEK_END);
readBuf=(char *)malloc(sizeof(char)*size+8);
lseek(fd1,0,SEEK_SET);
int n_read=read(fd1,readBuf,size);
int n_write=write(fd2,readBuf,strlen(readBuf));
exit(0);}
else {
pc=wait(&status);
printf("我是父进程,我等待的子进程的id号=%d\n",pc);
close(fd1);
close(fd2);
return 0;}
}