2023.09.08

#include 
int main(int argc, const char *argv[])
{
	int fp=open(argv[1],O_RDONLY);
	int cp=open("./cp.png",O_WRONLY|O_APPEND|O_CREAT,0777);
	off_t a=lseek(fp,0,SEEK_END);
	off_t b=a/2;
	lseek(fp,0,SEEK_SET);
	char s;
	int i=0;
	while(1){
		read(fp,&s,1);
		i++;
		write(cp,&s,1);
		if(b==i){break;}
	}
	pid_t cpid=fork();
	if(0==cpid){
		//sleep(5);
		char s;
		while(1){
			ssize_t res=read(fp,&s,1);
			if(0==res){exit(1);}
			write(cp,&s,1);
		}
	}
	while(1){
		sleep(1);
	}
	close(fp);
	close(cp);
	return 0;
}

你可能感兴趣的:(java,前端,算法)