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

📄 asyncmonitor.c

📁 宋宝华的《Linux设备驱动开发详解》第一版的源代码
💻 C
字号:
/*======================================================================    A test program to access /dev/second    This example is to help understand async IO         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 <signal.h>#include <unistd.h>/*接收到异步读信号后的动作*/void input_handler(int signum){  printf("receive a signal from globalfifo,signalnum:%d\n",signum);}main(){  int fd, oflags;  fd = open("/dev/globalfifo", O_RDWR, S_IRUSR | S_IWUSR);  if (fd !=  - 1)  {    //启动信号驱动机制    signal(SIGIO, input_handler); //让input_handler()处理SIGIO信号    fcntl(fd, F_SETOWN, getpid());    oflags = fcntl(fd, F_GETFL);    fcntl(fd, F_SETFL, oflags | FASYNC);    while(1)    {    	sleep(100);    }  }  else  {    printf("device open failure\n");  }}

⌨️ 快捷键说明

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