📄 linux设备驱动程序学习(5)-高级字符驱动程序操作[(2)阻塞型i-o和休眠] - linux设备驱动程序 - tekkaman ninja.htm
字号:
style="COLOR: rgb(0,0,204)">[</SPAN>kseriod<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 77
root SW <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>pdflush<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 78
root SW <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>pdflush<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 79
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>kswapd0<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 80
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>aio<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 707
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>mtdblockd<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 708
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>nftld<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 709
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>inftld<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 710
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>rfdd<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 742
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>kpsmoused<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 751
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>kmmcd<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 769
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>rpciod<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 778
root 1752 S <SPAN
style="COLOR: rgb(0,0,204)">-</SPAN>sh<BR> 779
root 1744 S init<BR> 781 root 1744 S
init<BR> 783 root 1744 S
init<BR> 787 root 1744 S
init<BR> <SPAN
style="COLOR: rgb(255,1,2)"> 799 root 1336
S ./sleepy_testr</SPAN><BR> 804 root
1744 R ps<BR><SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>Tekkaman2440@SBC2440V4<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><SPAN
style="COLOR: rgb(0,0,204)">#</SPAN><SPAN
style="COLOR: rgb(0,0,204)">.</SPAN><SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>sleepy_testw<BR><SPAN
style="COLOR: rgb(255,0,0)">write</SPAN>
code<SPAN
style="COLOR: rgb(0,0,204)">=</SPAN>0<BR><SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>Tekkaman2440@SBC2440V4<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><SPAN
style="COLOR: rgb(0,0,204)">#</SPAN><SPAN
style="COLOR: rgb(255,0,0)">read</SPAN>
code<SPAN
style="COLOR: rgb(0,0,204)">=</SPAN>0<BR><BR><SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>1<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">+</SPAN> Done <SPAN
style="COLOR: rgb(0,0,204)">.</SPAN><SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>sleepy_testr<BR><SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>Tekkaman2440@SBC2440V4<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><SPAN
style="COLOR: rgb(0,0,204)">#</SPAN>ps<BR> PID
Uid VSZ Stat
Command<BR> 1 root 1744 S
init<BR> 2 root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>kthreadd<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 3
root SWN <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>ksoftirqd<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 4
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>watchdog<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 5
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>events<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 6
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>khelper<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 59
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>kblockd<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 60
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>ksuspend_usbd<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 63
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>khubd<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 65
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>kseriod<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 77
root SW <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>pdflush<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 78
root SW <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>pdflush<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 79
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>kswapd0<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 80
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>aio<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 707
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>mtdblockd<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 708
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>nftld<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 709
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>inftld<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 710
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>rfdd<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 742
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>kpsmoused<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 751
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>kmmcd<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 769
root SW<SPAN
style="COLOR: rgb(0,0,204)"><</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>rpciod<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN><BR> 778
root 1752 S <SPAN
style="COLOR: rgb(0,0,204)">-</SPAN>sh<BR> 779
root 1744 S init<BR> 781 root 1744 S
init<BR> 783 root 1744 S
init<BR> 787 root 1744 S
init<BR> 806 root 1744 R
ps</SPAN></CODE></P></TD></TR></TBODY></TABLE>
<P>
<HR id=null>
<BR><FONT color=#0000ff
size=4><STRONG>阻塞和非阻塞操作</STRONG></FONT><BR>
<P></P>
<P>全功能的 read 和 write 方法涉及到进程可以决定是进行非阻塞 I/O还是阻塞
I/O操作。明确的非阻塞 I/O 由 filp->f_flags 中的 O_NONBLOCK
标志来指示(定义再 <FONT
color=#0000ff><linux/fcntl.h></FONT> ,被
<FONT
color=#0000ff><linux/fs.h></FONT>自动包含)。浏览源码,会发现O_NONBLOCK
的另一个名字:O_NDELAY ,这是为了兼容 System V 代码。O_NONBLOCK
标志缺省地被清除,因为等待数据的进程的正常行为只是睡眠. </P>
<P>其实不一定只有read 和 write
方法有阻塞操作,open也可以有阻塞操作。后面会见到。而我的项目有一个和CPLD的接口的驱动,我决定要在ioctl
中使用阻塞。</P>
<P>以下是后面的scullpipe实验的有关阻塞的代码,我觉得写得很好,先结合书上的介绍看看吧:</P>
<TABLE style="B
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -