动手写linux驱动(5)--Apple的学习笔记

一,前言

昨天完成了同步io,今天就练习一个异步io。
工程7就是在echo像文件写入值的时候调用kill_fasync发送信号给用户回调接口。
源码上传在我的gitee上https://gitee.com/applecai/linux-driver-study。

二,遇到的问题

  1. fcntl少写了F_SETFL,导致无信号效果。
  2. 一开始没用fd,用了STDIN_FILENO,效果变成了没有用echo直接在控制台输入任何信号,驱动就会发出kill。

三,效果测试

通过echo像设备写任何值,则激活信号。

# insmod applepaper7.ko
[   15.647543] applepaper7: loading out-of-tree module taints kernel.
[   15.655445] Registered character driver
[   15.659527] Registered character driver
[   15.664798] Registered character driver
# ./applepaper7 /dev/applepaper6 &
# echo a >/dev/applepaper6
[   22.421048] fasync
[   32.776802] written 2 bytes,current_len:2
[   32.783033] applepaper_write kill SIGIO
received a signal(29) from applepaper
# echo b >/dev/applepaper6
[   32.787357] fasync
[   41.455212] written 2 bytes,current_len:4
[   41.461343] applepaper_write kill SIGIO
received a signal(29) from applepaper
# echo "hi" >/dev/applepaper6
[   41.466027] fasync
[   50.056254] written 3 bytes,current_len:7
[   50.062380] applepaper_write kill SIGIO
received a signal(29) from applepaper

你可能感兴趣的:(动手写linux驱动(5)--Apple的学习笔记)