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

📄 second_test.c

📁 宋宝华的《Linux设备驱动开发详解》第一版的源代码
💻 C
字号:
/*======================================================================    A test program to access /dev/second    This example is to help understand kernel timer         The initial developer of the original code is Baohua Song    <author@linuxdriver.cn>. All Rights Reserved.======================================================================*/#include <sys/types.h>#include <sys/stat.h>#include <stdio.h>#include <fcntl.h>#include <unistd.h>#include <sys/time.h>main(){  int fd;  int counter = 0;  int old_counter = 0;    /*打开/dev/second设备文件*/  fd = open("/dev/second", O_RDONLY);  if (fd !=  - 1)  {    while (1)    {      read(fd,&counter, sizeof(unsigned int));//读目前经历的秒数      if(counter!=old_counter)      {	      	printf("seconds after open /dev/second :%d\n",counter);      	old_counter = counter;      }	    }      }  else  {    printf("Device open failure\n");  }}

⌨️ 快捷键说明

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