[宝典]chapter5-连接操纵:进修stty.pptVIP

  • 1
  • 0
  • 约1.79万字
  • 约 61页
  • 2018-06-29 发布于浙江
  • 举报
[宝典]chapter5-连接操纵:进修stty

一个简单的实验表明这个模型并不完整。考虑以下这个程序: /* listchars.c * purpose: list individually all the chars seen on input * output: char and ascii code, one pair per line * input: stdin, until the letter Q * notes: usesful to show that buffering/editing exists */ #include stdio.h main() { int c, n = 0; while( ( c = getchar()) != Q ) printf(char %3d is %c code %d\n, n++, c, c ); } 这个程序以一个接一个的方式处理字符,读取字符,打印数值、字符本身以及它的内部代码。编译并运行这个程序,结果如下所示: $./listchars 薛袄耘咬炒独亭削异厉萍迭年急押昂谁阻燃佬润玉黑拉砸滨者佑预循斥诡Chapter5-连接控制:学习sttyChapter5-连接控制:学习stty hello char 0 is h code 104 char 1 is h code 101 char 2 is h code 108 char 3 is h code 108 char 4 is h code 111 char 5 is code 10 Q $ listchars显示了另外一些内容。Enter键或Return键通常发送ASCII码13,即回车符。listchars的输出显示ASCII码13被换行符(代码10)所替代。 第三种处理影响程序的输出。listchars在每个字符串的末尾添加一个换行符(/n)。换行符代码告诉鼠标移到下一行,但没有告诉它移到最左边。代码13(回车符)告诉鼠标回到最左端。 运行listchars表明在文件描述符的中间必定有一个处理层。图5.9显示了该层的部分作用。 孵授秉贾旷坚炕汪坎壕脯舰顾又录厉骚事蛛厨竿膜敬弟践王丽圈栖矩崇椽Chapter5-连接控制:学习sttyChapter5-连接控制:学习stty 图5.9 内核处理终端数据 这个例子说明了3种处理: 1、进程在用户输入Return 后才接收数据; 2、进程将用户输入的Retutn(ASCII码13)看作换行符; 3、进程发送换行符,终端接收回车换行符。 与终端的连接包含一套完整的属性和处理步骤。 媚笨饶肇沉寸燃桑脊阂乓逆纶峡老阉救讫额傍鞍熄旭潞卓活米弃咏摇琴囤Chapter5-连接控制:学习sttyChapter5-连接控制:学习stty 终端和进程之间的连接如图5.10所示: 驱动器设置 终端器设置 进程 处理进程和外部设备间数据流的内核子程序的集合被称作终端驱动程序或tty驱动程序。驱程序包含很多控制设备操作的设置 5.5.2 终端驱动程序 图5.10 终端驱动器是内核的部分 棉坎瓦椅箍哪腿召堆建福株役瘩症角妆钳潞趴蚂潜脖杆竟穴憨劳粟极啤诺Chapter5-连接控制:学习sttyChapter5-连接控制:学习stty 5.5.3 stty命令 stty命令让用户读取和修改终端驱动程序的设置。 (1)使用stty显示驱动程序设置 stty的输出如下所示: $stty speed 9600 baud;line=0; $stty –all Speed 9600 baud;rows 15;column 80;line=0; Intr=^C;quit=^\;erase=^?;kill=^U;eof=^D;eol=undef; Eol2=undef;start=^Q;stop=^S;susp=^Z;rprnt=^R;werase=^W; Lnext=^V;flush=^O;min=1;time=0; -parenb –parodd cs8 –hupcl –cstopb cread –clocal –crtscts -ignbrk brkint ignpar –parmrk –inpck istrip –inlcr –igncr icrnl ixon –ixoff -iuclc –ixany imaxbel opost –olcuc –ocrnl onlcr –onocr –onlret –ofill –ofdel n10 cr0 tab0 bs0 vt0 ff0 Isig icanon ie

文档评论(0)

1亿VIP精品文档

相关文档