⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 globalvar_wait_5s.c

📁 Some simple source code to show specific function like mouse and graphic.
💻 C
字号:
#include <sys/types.h>#include <sys/stat.h>#include <stdio.h>#include <fcntl.h>#include <sys/time.h>#include <sys/types.h>#include <unistd.h>#include <time.h>#include <math.h>void function(){unsigned int i,j;double y;for(i=0; i<5000; i++) for(j=0; j<4000; j++)	y=1+1;}main(){int fd, num;fd_set rfds;struct timeval tv;#if 0time_t t;struct tm nowtime, *pt=&nowtime;char *sTime;struct timeval tpstart, tpend;float timeuse;t=time(NULL);//pt=&nowtime;pt=localtime(&t);sTime=asctime(pt);printf("Now time is %s \n",sTime);gettimeofday(&tpstart,NULL);function();gettimeofday(&tpend,NULL);timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;//1 t.tv_sec = 1000000 t.tv_usec timeuse/=1000000;printf("Used Time:%f\n",timeuse);#endiffd = open("/dev/globalvar", O_RDWR, S_IRUSR | S_IWUSR);if (fd != - 1){	while (1)	{	FD_ZERO(&rfds);	FD_SET(fd, &rfds);	tv.tv_sec = 2;	tv.tv_usec = 0;		select(fd + 1, &rfds, NULL, NULL, &tv);	if (FD_ISSET(fd, &rfds))	{		read(fd, &num, sizeof(int));		printf("The globalvar is %d\n", num);			if (num == 0)		{			close(fd);			break;		}	}	else	printf("No data within 5 seconds.\n");	}}else{	printf("device open failure\n");}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -