599-601.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 96 行

HTML
96
字号
<HTML>

<HEAD>

<TITLE>Linux Unleashed, Third Edition:Devices</TITLE>

<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=0672313723//-->

<!--TITLE=Linux Unleashed, Third Edition//-->

<!--AUTHOR=Tim Parker//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Sams//-->

<!--CHAPTER=33//-->

<!--PAGES=599-601//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="597-599.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="601-604.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H4 ALIGN="LEFT"><A NAME="Heading16"></A><FONT COLOR="#000077">What Are /sbin/getty and /etc/gettydefs?</FONT></H4>

<P>The <TT>sbin/getty</TT> (<TT>/etc/getty</TT> on some systems) program is referred to quite a lot when dealing with terminals, but people often don&#146;t clearly understand what the program does. Quite simply, <TT>/sbin/getty</TT> is a binary program that sets the communications parameters between Linux and a terminal, including the speed, protocol, and any special handling of the cable.</P>

<P>The <TT>/sbin/getty</TT> program is called by <TT>/etc/init</TT> when a user is logging in. When called, <TT>/sbin/getty</TT> opens the serial port or other connection to the terminal and sets the communications parameters based on information in the file <TT>/etc/gettydefs</TT> (<TT>getty</TT> definitions). The <TT>getty</TT> process then generates the login prompt on the remote terminal.</P>

<P>Many special handling and command options are available with the <TT>getty</TT> process, but most of them are of little interest to users and casual system administrators. If you want complete information on the <TT>getty</TT> command, consult the man pages that accompany Linux.</P>

<P>The <TT>/etc/gettydefs</TT> file is used to supply the settings <TT>getty</TT> uses for communications. The format of each line in the <TT>gettydefs</TT> file is as follows:</P>

<!-- CODE SNIP //-->

<PRE>

<I>label:initial flags: final flags: login prompt: next label</I>

</PRE>

<!-- END CODE SNIP //-->

<P>The <I><TT>label</TT></I> is used to identify each line, so that when <TT>/sbin/getty</TT> is started with an argument (as it usually is, transparent to the user), the argument is used to match the <I><TT>label</TT></I> and provide the configuration information. The <I><TT>initial</TT></I> and <I><TT>final</TT></I> flags are used to set any behavior for the connection before and after the <TT>login</TT> program has executed.</P>

<P>The <I><TT>login prompt:</TT></I> is the prompt to be displayed on the terminal. Usually it is just <TT>login:</TT>, but it can be any string. Finally, the <I><TT>next label</TT></I> is used to send <TT>getty</TT> to another line, in case it can&#146;t use the current one. This is typically used with modem lines, which start at a high speed (such as 9600 baud) and go to 4800, 2400, and 1200 in sequence, trying to connect at each step. For terminals, the <TT>next label</TT> is usually a pointer back to the line&#146;s first <TT>label</TT>.</P>

<P>An extract from a sample <TT>/etc/gettydefs</TT> file looks like this:</P>

<!-- CODE //-->

<PRE>

console# B19200 OPOST ONLCR TAB3 BRKINT IGNPAR ISTRIP IXON IXANY PARENB

ECHO

ECHOE ECHOK ICANON ISIG CS8 CREAD # B19200 OPOST ONLCR TAB3 BRKINT IGNPAR

ISTRIP

IXON IXANY PARENB ECHO ECHOE ECHOK ICANON ISIG CS8 CREAD #Console Login:

#console



9600H# B9600 # B9600 SANE IXANY PARENB TAB3 HUPCL #login: #4800H



4800H# B4800 # B4800 SANE IXANY PARENB TAB3 HUPCL #login: #2400H



2400H# B2400 # B2400 SANE IXANY PARENB TAB3 HUPCL #login: #1200H



1200H# B1200 # B1200 SANE IXANY PARENB TAB3 HUPCL #login: #300H



300H# B300 # B300 SANE IXANY PARENB TAB3 HUPCL #login: #9600H

</PRE>

<!-- END CODE //-->

<P>If you look at the file that accompanies your Linux system, you see that there are many more lines, but they all have the same format as the preceding examples. The easiest lines to look at are the shorter ones (the last five lines in the preceding extract), but they all have the same format as the preceding examples.

</P>

<P>These lines are for a modem, starting at 9600 baud. The initial flag is set to <TT>B9600</TT>, which sets the baud rate at 9600 baud. The final flags, used when a connection has been established, set the characteristics of the line (such as a <TT>TAB</TT> meaning three spaces). Finally, the field at the end points to the next lower speed to provide checks for slower modems or poor lines that prevent fast logins.</P>

<P>The first line in the preceding extract is typical for a terminal. It sets many initial and final flags that control how the terminal behaves. The reference at the end of the line is back to the same definition, because the terminal is hard-wired to the system.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>Note:&nbsp;&nbsp;</B><BR>You shouldn&#146;t have to change the entries in the <TT>gettydefs</TT> file, because the default file contains many different configurations. You should examine the file carefully to find an entry that works with the terminal you are using. If you do make changes to the <TT>gettydefs</TT> file, you should run the command <TT>getty -c gettydefs</TT> to make the changes effective.<HR></FONT>

</BLOCKQUOTE>

<P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="597-599.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="601-604.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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