⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch42_01.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 42] Problems with Terminals</TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:52:19Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="part07.htm"TITLE="VII. Terminals and Printers "><LINKREL="prev"HREF="ch41_12.htm"TITLE="41.12 Finding Out What Characters Your Terminal's Special Keys Send"><LINKREL="next"HREF="ch42_02.htm"TITLE="42.2 Fixing a Hung Terminal or Job "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch41_12.htm"TITLE="41.12 Finding Out What Characters Your Terminal's Special Keys Send"><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 41.12 Finding Out What Characters Your Terminal's Special Keys Send"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 42</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch42_02.htm"TITLE="42.2 Fixing a Hung Terminal or Job "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 42.2 Fixing a Hung Terminal or Job "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="CHAPTER"><H1CLASS="chapter"><ACLASS="title"NAME="UPT-CHP-42">42. Problems with Terminals</A></H1><DIVCLASS="htmltoc"><P><B>Contents:</B><BR><ACLASS="sect1"HREF="#UPT-ART-1142"TITLE="42.1 Making Sense Out of the Terminal Mess ">Making Sense Out of the Terminal Mess </A><BR><ACLASS="sect1"HREF="ch42_02.htm"TITLE="42.2 Fixing a Hung Terminal or Job ">Fixing a Hung Terminal or Job </A><BR><ACLASS="sect1"HREF="ch42_03.htm"TITLE="42.3 Why Changing TERM Sometimes Doesn't Work ">Why Changing TERM Sometimes Doesn't Work </A><BR><ACLASS="sect1"HREF="ch42_04.htm"TITLE="42.4 Checklist for Resetting a Messed Up Terminal ">Checklist for Resetting a Messed Up Terminal </A><BR><ACLASS="sect1"HREF="ch42_05.htm"TITLE="42.5 Checklist: Screen Size Messed Up? ">Checklist: Screen Size Messed Up? </A><BR><ACLASS="sect1"HREF="ch42_06.htm"TITLE="42.6 Screen Size Testing Files ">Screen Size Testing Files </A><BR><ACLASS="sect1"HREF="ch42_07.htm"TITLE="42.7 termtest: Send Repeated Characters to Terminal ">termtest: Send Repeated Characters to Terminal </A><BR><ACLASS="sect1"HREF="ch42_08.htm"TITLE="42.8 Errors Erased Too Soon? Try These Workarounds ">Errors Erased Too Soon? Try These Workarounds </A></P><P></P></DIV><DIVCLASS="sect1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1142">42.1 Making Sense Out of the Terminal Mess </A></H2><PCLASS="para">When you're sitting in front of a terminal, it's sometimes hard torealize that you're face to face with about twenty-five years ofaccumulated history, with hack piled upon hack to deal withevolutions in hardware.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46486"></A>When you type at a terminal, you are really dealing with fourthings: </P><OLCLASS="orderedlist"><LICLASS="listitem"><PCLASS="para">The shell, utility, or applicationthat interprets and responds to what you type.</P></LI><LICLASS="listitem"><PCLASS="para">The UNIX kernel, or more specifically, the serial line driver, which may perform some low-level conversions on what you typebefore it's even passed to the program you think you're talking to.</P></LI><LICLASS="listitem"><PCLASS="para">The terminal, which has behavior of its own&nbsp;- and may locally interpretor respond to some of what you type instead of, or as well as,passing it through to the system.</P></LI><LICLASS="listitem"><PCLASS="para">The communication link between the terminal and the system.</P></LI></OL><PCLASS="para">Some of the confusion about UNIX terminal handling comes from thefact that there are mechanisms for dealing with each of theselayers.Let's take the list in the reverse order this time:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46502"></A><ACLASS="indexterm"NAME="AUTOID-46504"></A><ACLASS="indexterm"NAME="AUTOID-46506"></A>Most ASCII terminals, or <EMCLASS="emphasis">tty</EM>s, are connected to the system by a<EMCLASS="emphasis">serial line</EM>-a set of up to 24 wires defined by the RS-232 standard.Aremote terminal may be connected to a modem by a serial line; if thisis the case, the computer too must be connected to a modem, and thetwo modems talk to each other over the telephone.Some serial lineconfiguration happens at the hardware level.For example, not everycable includes every wire called for in the RS-232 standard, and boththe terminal and the system or modem have to agree to such things as whichone will talk over which wire.(Actually, both computer systems andterminals are quite stubborn about this; they have fixed ideas aboutwhich wire to talk on, and which to listen on, and if both want touse the same one, it's up to the system administrator to trick themby crossing the wires.)</P><PCLASS="para">There's more to the communications link than just the wires, though.For example, both the terminal and the system or modem have to be configured to agree on such things as how many data bits make up acharacter (a byte is made up of eight bits, but ASCII characters onlyrequire seven), whether or not to use parity (a simple form of errorchecking), how to &quot;frame&quot; each character with &quot;start&quot; and &quot;stop&quot;bits, and how fast to communicate (the baud rate).</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46512"></A><ACLASS="indexterm"NAME="AUTOID-46514"></A>All of these things are usually configured in advance&nbsp;- if theyweren't, the system and terminal couldn't talk to each other.However, the <SPANCLASS="link"><EMCLASS="emphasis">stty</EM> command (<ACLASS="linkend"HREF="ch41_02.htm"TITLE="stty and All That Stuff ">41.2</A>, <ACLASS="linkend"HREF="ch41_03.htm"TITLE="Find Out Terminal Settings with stty ">41.3</A>)</SPAN>does let you change these parameters on the fly (at least on the system side&nbsp;- your terminal may have a setup key and a built-in setup menu).You'd better know what you're doing, though, or you may render your terminal and computer unable to communicate.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46521"></A><ACLASS="indexterm"NAME="AUTOID-46523"></A><ACLASS="indexterm"NAME="AUTOID-46525"></A><ACLASS="indexterm"NAME="AUTOID-46527"></A>At least when UNIX started out, there were no standards for howterminals worked.A screen size of 24 lines and 80 columns became a(fairly) common denominator, but the special keys on terminal keyboards generate different characters, and each terminal might respondto different<SPANCLASS="link">escape sequences (<ACLASS="linkend"HREF="ch05_08.htm"TITLE="Terminal Escape Sequences ">5.8</A>)</SPAN>for moving the cursor around the screen, highlighting text in inversevideo, underlining, and so on.The <SPANCLASS="link"><EMCLASS="emphasis">termcap</EM> and <EMCLASS="emphasis">terminfo</EM> databases (<ACLASS="linkend"HREF="ch05_02.htm"TITLE="The Idea of a Terminal Database ">5.2</A>)</SPAN>were developed to make sense out of this babel.Once a terminal'scharacteristics are described in the database, a screen-orientedprogram like <EMCLASS="emphasis">vi</EM> can look up the information it needs to clearthe screen, move around, and so on.Programs like<SPANCLASS="link"><EMCLASS="emphasis">tset</EM> (<ACLASS="linkend"HREF="ch05_11.htm"TITLE="Initializing the Terminal with tset ">5.11</A>)</SPAN>and <SPANCLASS="link"><EMCLASS="emphasis">tput</EM> (<ACLASS="linkend"HREF="ch05_12.htm"TITLE="Initializing the Terminal with tput ">5.12</A>, <ACLASS="linkend"HREF="ch41_10.htm"TITLE="Using terminfo Capabilities in Shell Programs ">41.10</A>)</SPAN>were created to read the terminal database and use the information itcontains to issue commands (in the form of escape sequences) to the terminal.If you always use the same kind of terminal, you can configure your terminal by<SPANCLASS="link">issuing the escape sequences directly (<ACLASS="linkend"HREF="ch41_09.htm"TITLE="Commands to Adjust Your Terminal ">41.9</A>)</SPAN>.You don't need to look them up in the terminal database.(That's only important if you want a program or script to work with a varietyof terminals.)</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46541"></A>The serial line driver does various things to the characters it getsfrom the terminal.For example, in normal use, it changes the carriage return(ASCII character \015) generated by the RETURN key on your keyboardinto a linefeed (ASCII character \012).Chris Torek talks aboutsome of these conversions in article<ACLASS="xref"HREF="ch41_02.htm"TITLE="stty and All That Stuff ">41.2</A>.For the most part, unless you are a programmer or a systemadministrator, you don't need to know a whole lot about all of thepossibilities&nbsp;- but you do need to know that they are configurable,and that <SPANCLASS="link"><EMCLASS="emphasis">stty</EM> (<ACLASS="linkend"HREF="ch41_03.htm"TITLE="Find Out Terminal Settings with stty ">41.3</A>)</SPAN>is the program that reports (and<SPANCLASS="link">changes (<ACLASS="linkend"HREF="ch05_09.htm"TITLE="Setting Your Erase, Kill, and Interrupt Characters ">5.9</A>)</SPAN>)the settings.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46548"></A>Not all of the terminal driver settings are obscure.Some of themyou use every day, and must be sure to set in your<SPANCLASS="link"><EMCLASS="emphasis">.login</EM> or <EMCLASS="emphasis">.profile</EM> file (<ACLASS="linkend"HREF="ch02_03.htm"TITLE="What Goes in Shell Setup Files? ">2.3</A>)</SPAN>.For example, how does the system know thatyou want to use CTRL-c to interrupt a program or CTRL-s to stopoutput, or CTRL-z to suspend execution?This happens at a levelbelow even the shell&nbsp;- the shell never even sees these characters,because they are interpreted and acted on by the serial line driver.However, there are times when they <EMCLASS="emphasis">aren't</EM> interpreted.Haveyou ever typed CTRL-z when you're in <EMCLASS="emphasis">vi</EM>'s insert mode?Instead of<EMCLASS="emphasis">vi</EM> being suspended, the character is input.That's because<EMCLASS="emphasis">vi</EM> needs to<SPANCLASS="link">reset the serial driver to a different mode (<ACLASS="linkend"HREF="ch41_02.htm"TITLE="stty and All That Stuff ">41.2</A>)</SPAN>so that it has control over which characters are echoed and which areinterpreted as commands.</P><PCLASS="para">All of this is by way of saying that there's an awful lot ofcomplexity under the skin.</P></LI><LICLASS="listitem"><PCLASS="para">And, of course, as we've talked about at length in the discussionof wildcards and<SPANCLASS="link">quoting (<ACLASS="linkend"HREF="ch08_14.htm"TITLE="Bourne Shell Quoting ">8.14</A>)</SPAN>,the shell may intercept and act on various characters before passingthem on to another program.</P></LI></UL><PCLASS="para">The point of this long excursion is to suggest that when you aretrying to figure out problems with terminals, you owe it toyourself to know about all the levels where the problems can occur.(For example, article<ACLASS="xref"HREF="ch08_20.htm"TITLE="How Many Backslashes?">8.20</A>is about backslash handling.)</P><PCLASS="para">Are the terminal and computer system properly configured?Has the cable come loose?Is theterminal type set correctly so that programs know how to make thatparticular terminal do their bidding?Has an interrupted programsent out unfinished commands that left the terminal in aninconsistent or unusual state?Is it really a terminal problem, oris it just that things aren't working quite the way you expect?</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">TOR</SPAN></P></DIV></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch41_12.htm"TITLE="41.12 Finding Out What Characters Your Terminal's Special Keys Send"><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 41.12 Finding Out What Characters Your Terminal's Special Keys Send"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch42_02.htm"TITLE="42.2 Fixing a Hung Terminal or Job "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 42.2 Fixing a Hung Terminal or Job "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">41.12 Finding Out What Characters Your Terminal's Special Keys Send</TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">42.2 Fixing a Hung Terminal or Job </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -