📄 asyncmonitor.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 + -