0225-0227.html

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

HTML
380
字号


<HTML>

<HEAD>

<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:Filesystems, Disks, and Other Devices</TITLE>

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

 -->




<!-- ISBN=0672311739 //-->

<!-- TITLE=RED HAT LINUX 2ND EDITION //-->

<!-- AUTHOR=DAVID PITTS ET AL //-->

<!-- PUBLISHER=MACMILLAN //-->

<!-- IMPRINT=SAMS PUBLISHING //-->

<!-- PUBLICATION DATE=1998 //-->

<!-- CHAPTER=11 //-->

<!-- PAGES=0195-0228 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->









<P><CENTER>

<a href="0222-0224.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0228-0228.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-225"><P>Page 225</P></A>













<H4><A NAME="ch11_ 32">

The Controlling Terminal Device&#151;/dev/tty



</A></H4>









<P>Most processes have a controlling terminal, particularly if they were started interactively by

a user. The controlling terminal, which I'll refer to as simply

/dev/tty, is used for initiating a conversation directly with the user (for example, to ask them something). An example is

the crypt command:

</P>





<!-- CODE SNIP //-->

<PRE>

$ fmt diary.txt | crypt | mail -s Diary confidant@linux.org

Enter key:

$

</PRE>

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











<P>Here, the crypt command has opened /dev/tty in order to obtain a password. It was not

able to use its own standard output to issue the prompt and its standard input to read the

password because these are being used for the data to be encrypted.

</P>

<P>

<P>



<CENTER>

<TABLE BGCOLOR="#FFFF99">

<TR><TD><B>

NOTE

</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

Of course, it's unusual to send e-mail encrypted with

crypt. A better choice is probably PGP. PGP is available in RPM format from

ftp://ftp.replay.com//pub/linux/redhat.

</BLOCKQUOTE></TD></TR>

</TABLE></CENTER>

</P>

<P>More useful examples of this are commands that need to ask the operator something even

if their input and output are redirected. A case in point is the

cpio command, which prompts the operator for the name of a new tape device when it runs out of space. See the section

&quot;/dev/null and Friends&quot; later in this chapter for another

example.

</P>









<H4><A NAME="ch11_ 33">

Nonserial Mice



</A></H4>









<P>Many computers have bus or PS/2 mice instead of serial mice. This has the advantage of

keeping both of the two standard serial ports free, but the disadvantage of using up another

IRQ. These devices are used by gpm and the X Window System, but most other programs don't

interact with them directly. Setting up your system with these mice is quite easy; the Red

Hat Linux installation process pretty much takes care of it for you. Should you have problems

with your mouse, though, you should read the manual page for

gpm and the Linux BusMouse-HOWTO.

</P>









<H4><A NAME="ch11_ 34">

Audio Devices



</A></H4>









<P>There are several audio-related device nodes on Linux systems, and they include the following:</P>



<TABLE WIDTH="360">

<TR><TD>

/dev/sndstat

</TD><TD>

Indicates the status of the sound driver

</TD></TR>

<TR><TD>

/dev/audio*

</TD><TD>

Sun-compatible audio output device

</TD></TR>

<TR><TD>

/dev/dsp*

</TD><TD>

Sound sampling device

</TD></TR>

<TR><TD>

/dev/mixer

</TD><TD>

For control of the mixer hardware on the sound card

</TD></TR>

<TR><TD>

/dev/music

</TD><TD>

A high-level sequencer interface

</TD></TR>

</TABLE>



<A NAME="PAGENUM-226"><P>Page 226</P></A>



<TABLE WIDTH="360">

<TR><TD>

/dev/sequencer*

</TD><TD>

A low-level sequencer interface

</TD></TR>

<TR><TD>

/dev/midi*

</TD><TD>

Direct MIDI port access

</TD></TR>

<TABLE>











<P>Setting up the sound driver under Linux can sometimes be quite difficult, but the Linux

Sound-HOWTO provides useful advice.

</P>









<H5><A NAME="ch11_ 35">Random Number Devices

</A></H5>









<P>Many aspects of computing require the generation of apparently random sequences.

Examples include games, numerical computations, and various computer security related

applications. Numerical computing with random numbers requires that the sequence of random

numbers be repeatable but also that the sequence &quot;looks&quot; random. Games require apparently

random numbers too, but the quality of the random numbers used is not quite as critical as for

numerical computation programs. The system libraries produce repeatable sequences of &quot;pseudo-

random&quot; numbers that satisfy these requirements well.

</P>







<P>

On the other hand, there are many aspects of computer security in which it is advantageous

to generate numbers that really are random. Because you can assume that an attacker has

access to the same sorts of random number generators that you do, using these is usually not

very safe&#151;an attacker can use these generators to figure out what random number you'll come

out with next. Sequences that are genuinely random must in the end be produced from the

real world, and not from the internals of some computer program. For this reason, the Linux

kernel keeps a supply of random numbers internally. These numbers are derived from very

precise timings of the intervals between &quot;random&quot; external events&#151;for example, the user's

keypresses on the keyboard, mouse events, and even some interrupts (such as from the floppy disk

drive and some network cards). These &quot;real&quot; random numbers are used in security-critical

contexts&#151;for example, the choosing of TCP sequence numbers.

</P>



<CENTER>

<TABLE BGCOLOR="#FFFF99">

<TR><TD><B>

NOTE

</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

The Linux kernel uses these methods to produce TCP sequence numbers that are

more difficult to guess than those of any other implementation at the time of writing. This

improves the security of TCP connections against &quot;hijacking.&quot;

</BLOCKQUOTE></TD></TR>

</TABLE></CENTER>

</P>

<P>The two random number devices differ in what happens when the rate of reading exceeds

the rate at which random data is collected inside the kernel. The

/dev/random device makes the calling program wait until some more randomness arrives, and the

/dev/urandom device falls back on the difficult-to-guess MD5 hash to produce a stream of random data. When

more random information arrives later, this is added to the randomness of

/dev/urandom. To summarize, /dev/random doesn't sacrifice quality in favor of speed, but

/dev/urandom does.

</P>



<A NAME="PAGENUM-227"><P>Page 227</P></A>













<H4><A NAME="ch11_ 36">

/dev/null and Friends



</A></H4>









<P>In the following, the special devices /dev/full and

/dev/null first simulate a tape-full condition and then discard the output:

</P>





<!-- CODE SNIP //-->

<PRE>

$ echo diary.txt | cpio -o &gt;/dev/full

Found end of tape.  To continue, type device/file name when ready.

/dev/null

52 blocks

</PRE>

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











<P>In the real world, when the tape on /dev/st0 became full, you would probably just have

changed the tape in the drive and typed /dev/st0 a second time. However,

/dev/full is occasionally useful for testing purposes, and

/dev/null is used all the time for discarding unwanted

output. The device /dev/zero produces a stream of zero bytes when read.

(/dev/null, on the other hand, produces no output

at all.)

</P>









<H4><A NAME="ch11_ 37">

Memory Devices

</A></H4>









<P>The memory devices have the same major device number as

/dev/null and /dev/full, but are used very differently. They are as follows:

</P>



<TABLE WIDTH="360">



<TR><TD>

/dev/mem

</TD><TD>

Provides access to physical memory

</TD></TR>

<TR><TD>

/dev/kmem

</TD><TD>

Provides access to the kernel's virtual memory

</TD></TR>

<TR><TD>

/dev/port

</TD><TD>

Provides access to I/O ports

</TD></TR>

</TABLE>













<P>These devices are not frequently used in many programs; the X Window System's X server

uses memory mapping on /dev/mem to access the video memory, and many programs use

/dev/port to access I/O ports on those architectures that have a separate I/O space. (Many modern

processors do not.)

</P>









<H4><A NAME="ch11_ 38">

Virtual Console Screen Devices

</A></H4>









<P>The virtual console screen devices exist to provide screen capture capabilities for virtual

consoles (VCs). They are not readable by ordinary users; hence, other users cannot eavesdrop

on your session.

</P>









<P>There are two sets of device nodes for this purpose:</P>





<!-- CODE SNIP //-->

<PRE>

$ ls -l /dev/vcs[012] /dev/vcsa[012]

crw--w----   1 root     tty        7,   0 Sep 27  1995 /dev/vcs0

crw--w----   1 root     tty        7,   1 Sep 27  1995 /dev/vcs1

crw--w----   1 root     tty        7,   2 Sep 27  1995 /dev/vcs2

crw--w----   1 root     tty        7, 128 Sep 27  1995 /dev/vcsa0

crw--w----   1 root     tty        7, 129 Sep 27  1995 /dev/vcsa1

crw--w----   1 root     tty        7, 130 Sep 27  1995 /dev/vcsa2

</PRE>

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











<P>Each set is numbered from 0 to 63, corresponding to the numbering system for the

/dev/tty* console devices. The device /dev/vcs0, like the device

dev/tty0, always refers to the currently selected VC.

</P>



<P><CENTER>

<a href="0222-0224.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0228-0228.html">Next</A>

</CENTER></P>









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

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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