- 1、本文档共20页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
终端分析
终端分析
在linux系统中,所有的输入和输出都尽可能的做成象从普通文件的输入输出一样。但是,终端I/O是比较困难的情况之一。
通常,一个进程通过从它的双亲进程继承文件描述符0,1和2,被自动的附属于一个终端。这时,open()函数已经由进程完成,并且所附属的终端将是该进程的控制终端。
O_CREAT,O_EXCL,O_EXCL,O_TRUCN和O_APPEND标志用到终端文件时没有任何意义。但是,有两个新的标志有用
O_NOCTTY 停止这个终端作为控制终端。
O_NONBLOCK 使open(),read()和write()不被阻塞。
为了简化分析,我们主要分析主机console,即主设备号为4的设备,对应下图的Memory-mapped interface.
各种终端类型:
数据结构
struct tty_struct
tty.h
当一个tty打开时,它所有的状态存于此结构。有些信息即使tty关闭了也要维护,
如baud rate,所以它们被存放于另一个结构termios中。tty_struct用一个struct
指向它。由于本结构动态分配,所以它不能大于4096字节。
/*
* Where all of the state associated with a tty is kept while the tty
* is open. Since the termios state should be kept even if the tty
* has been closed for things like the baud rate, etc it is
* not stored here, but rather a pointer to the real state is stored
* here. Possible the winsize structure should have the same
* treatment, but (1) the default 80x24 is usually right and (2) it's
* most often used by a windowing system, which will set the correct
* size each time the window is created or resized anyway.
* IMPORTANT: since this structure is dynamically allocated, it must
* be no larger than 4096 bytes. Changing TTY_BUF_SIZE will change
* the size of this structure, and it needs to be done with care.
* - TYT, 9/14/92
*/
struct tty_struct {
int magic;
struct tty_driver driver; //驱动程序
struct tty_ldisc ldisc; //主要读写都是通过调用ldisc中的函数实现。
struct termios *termios, *termios_locked;
int pgrp; //相关进程的组识别号。
int session; //会话号。
kdev_t device; //设备号
unsigned long flags;
int count;
struct winsize winsize;
unsigned char stopped:1, hw_stopped:1, packet:1;
unsigned char ctrl_status;
struct tty_struct *link;
struct fasync_struct *fasync;
struct tty_flip_buffer flip;/*用于存放键盘传来的字符*/
int max_flip_cnt;
struct wait_queue *write_wait; /*写等待队列*/
struct wait_queue read_wait; /*读等待队列*/
void *disc_data;
void *driver_data;
#define N_TTY_BUF_SIZE 4096
/*
* The following is data for the N_TTY line discipline. For
* historical reas
文档评论(0)