IO进程线程day5

作业1

void *callback(void* arg)
{
	while(1)
	{   
		int fd = open("./11.png",O_RDONLY);
		if(fd<0)
		{
			perror("open");
			return -1;
		}

		int fd_w = open("./22.png",O_WRONLY|O_CREAT|O_TRUNC);
		if(fd<0)
		{
			perror("open");
			return -1;
		}
		char buf[128]="";
		ssize_t res=0;
		off_t size=lseek(fd,0,SEEK_SET);

		bzero(buf,sizeof(buf));
		int res=(fd,buf,sizeof(buf));                                                                                                                                                       
		off_t size=lseek(fd,size/2,SEEK_SET);
		if(0==res)
			break;
		write(fd_w,buf,res);


		printf("this is oher func __%d__\n",__LINE__);
	}   
	return NULL;
}


int main(int argc, const char *argv[])
{
	pthread_t tid;
	//创建一个线程,线程执行体为callback
	if(pthread_create(&tid,NULL,callback,NULL)!=0)
	{
		fprintf(stderr,"pthread_create failed __%d__",__LINE__); 
		return -1; 
	} 

	while(1)
	{
		int fd = open("./11.png",O_RDONLY);
		if(fd<0)
		{
			perror("open");
			return -1;
		}

		int fd_w = open("./22.png",O_WRONLY|O_CREAT|O_TRUNC);
		if(fd<0)
		{
			perror("open");
			return -1;
		}

		char buf[128]=""; 
		ssize_t res=0;
		off_t size=lseek(fd,size/2,SEEK_SET);


		bzero(buf,sizeof(buf));
		res=(fd,buf,sizeof(buf));
		if(size/2==res)
			break;
		write(fd_w,buf,res);

		printf("this is main func __%d__\n",__LINE__);
		sleep(5);
	}

	return 0;
}

作业2

void* callback(void* arg)
{
	char buf[] = "1234567";
	int i=0,j=strlen(buf)-1;
	while(1)
	{
		for( i=0;i

思维导图

你可能感兴趣的:(嵌入式硬件)