asyncmonitor.c
来自「Linux驱动编程源码」· C语言 代码 · 共 42 行
C
42 行
/*====================================================================== 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 + =
减小字号Ctrl + -
显示快捷键?