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

📄 ch01_14.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 1] 1.14 The Kernel and Daemons </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:31:12Z"><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="ch01_01.htm"TITLE="1. Introduction"><LINKREL="prev"HREF="ch01_13.htm"TITLE="1.13 Why Fundamentals Are Important "><LINKREL="next"HREF="ch01_15.htm"TITLE="1.15 Filenames "></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="ch01_13.htm"TITLE="1.13 Why Fundamentals Are Important "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 1.13 Why Fundamentals Are Important "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 1<BR>Introduction</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_15.htm"TITLE="1.15 Filenames "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 1.15 Filenames "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1007">1.14 The Kernel and Daemons </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="UPT-ART-1007-IX-KERNEL-DESCRIBED"></A><ACLASS="indexterm"NAME="UPT-ART-1007-IX-DAEMONS-DESCRIBED"></A>If you have arrived at UNIX via DOS or some otherpersonal computer operating system, you will notice some bigdifferences. UNIX is, was, and always will be a multiuser operatingsystem. It is a multiuser operating system even when you're the onlyperson using it. It is a multiuser operating system even when it isrunning on a PC with a single keyboard. And this fact has importantramifications for everything that you do.</P><PCLASS="para">Why does this make a difference? Well, for one thing, you're neverthe only one using the system, even when you think you are. Don'tbother to look under your desk to see if there's an extra terminalhidden down there. There isn't. But UNIX is always doing things&quot;behind your back,&quot; running programs of its own, whether or not youare aware of it. The most important of these programs, the<EMCLASS="emphasis">kernel</EM>, is the heart of the UNIX operating system itself.The kernelassigns memory to each of the programs that are running, partitionstime fairly so that each program can get its job done, handles all I/O(input/output) operations, and so on.Another important group of programs, called<EMCLASS="emphasis">daemons</EM>, are the system's &quot;helpers.&quot; They run from time totime performing small but important tasks like handling mail, runningnetwork communications, feeding data to your printer, keeping track ofthe time, and so on.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-1338"></A>You can use UNIX for a long time without being aware of the kernel orany of the daemons. If you suddenly see a &quot;panic&quot; message on yourterminal and your system stops in its tracks (crashes), you'vejust had a run-in with the kernel. Something has gotten the kernelconfused, and it has decided to give up rather than risk doingsomething foolish. And there's not much you can doto remedy a panic; the problem usually isn't your fault. But youshould know where they're coming from. Similarly, daemons mayoccasionally bombard you with messages. And when you give the<EMCLASS="emphasis">ps</EM> command (see the following list), there may be some names that you don't recognize.These are probably the names of daemons that happen to be doingsomething benevolent at the moment. Right now, we won't worryabout them. But you should know that they are there.</P><PCLASS="para">Not only are you sharing the computer with the kernel and somemysterious daemons, you're also sharing it with yourself.I am currently using a Sun 3 workstation. If I give the command<SPANCLASS="link"><EMCLASS="emphasis">ps</EM> (<ACLASS="linkend"HREF="ch38_05.htm"TITLE="The ps Command ">38.5</A>)</SPAN>,<ACLASS="indexterm"NAME="AUTOID-1344"></A>which lists all the programs I am running, I get the following report:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">PID TT STAT  TIME COMMAND 1449 co IW    0:01 sunview 1453 co S     0:27 clock -Wp 497 32 -WP 704 0 -Wi -Wh 1 1451 p0 IW    0:04 shelltool 1452 p0 IW    0:00 -bin/csh (csh) 1454 p1 R     2:52 shelltool 1455 p1 S     0:01 -bin/csh (csh) 2217 p1 R     0:00 ps 1504 p2 S     1:54 shelltool 1505 p2 IW    0:01 -bin/csh (csh) 1884 p2 S     1:32 emacs princip3.otl</PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-1350"></A>I may think that I'm only running the editor Emacs, but thecomputer is actually doing a lot more for me. I'm also running<EMCLASS="emphasis">sunview</EM>, which keeps track of Sun's display, and I'm running aprogram that displays a little clock in one corner of my screen.I'm running several &quot;command tools,&quot; which are windows (or areas ofthe screen) that act like separate terminals. Each command tool has a<EMCLASS="emphasis">shell</EM> (<EMCLASS="emphasis">csh</EM>), which is a command interpreter that decipherseverything I type at the keyboard. And I'm running the <EMCLASS="emphasis">ps</EM>command. And, waiting patiently somewhere, my lonelyEmacs editor is waiting for me to type some more.</P><PCLASS="para">If you are running the<SPANCLASS="link">X window system (<ACLASS="linkend"HREF="ch01_31.htm"TITLE="The X Window System ">1.31</A>)</SPAN>or if you're using acomputer with the System V <EMCLASS="emphasis">layers</EM> facility, you willsee something different. But we guarantee thatyou're running at least two programs, and quite likely many more. Ifyou want to see everything that's running, including the daemons, typethe command <CODECLASS="literal">ps&nbsp;-aux</CODE> (for BSD) or <CODECLASS="literal">ps&nbsp;-el</CODE>(for many other flavors of <EMCLASS="emphasis">UNIX</EM>). You'll be impressed.</P><PCLASS="para">Because there is so much going on at once, you have to get used to adifferent way of thinking about UNIX. The UNIX kernel is a trafficcop that mediates different demands for time, for memory, for disks,and so on. Not only does thekernel need to run your programs, but it also needs to run thedaemons, any programs that other users might want to start, or anyprograms that you may have scheduled to<SPANCLASS="link">run automatically (<ACLASS="linkend"HREF="ch40_01.htm#UPT-ART-2313"TITLE="Off-Peak Job Submission ">40.1</A>)</SPAN>.When itruns a program, the kernel allocates a small slice of time&nbsp;- up to asecond&nbsp;- and lets the program run until that slice is used up, or theprogram decides to take a rest of its own accord (this is called&quot;sleeping&quot;). At this point, whether or not the program is finished,the kernel finds some other program to run. The UNIX kernel nevertakes a vacation. It is always watching over the system.</P><PCLASS="para">Once you understand that the kernel is a manager that schedules manydifferent kinds of activity, you understand a lot about how UNIXworks. For example, if you have used any computer system previously,you know that it's a bad idea to turn the computer off while it iswriting something on the disk. You will probably destroy the disk,and could conceivably damagethe disk drive. The same is true for UNIX-but with an importantcomplication. Any of the programs that are running can start doingsomething to the disk at any time. One of the daemons makes a pointof accessing the disk drive every 30 seconds or so, just to stay intouch. Therefore, you can't just turn a UNIX computer off. You mightdo all sorts of damage to the system's files&nbsp;- and not just your own,but conceivably files belonging to many other users. To turn aUNIX system off, you must first run a program called <EMCLASS="emphasis">shutdown</EM>,<ACLASS="indexterm"NAME="AUTOID-1367"></A>which kicks everyone off the system and makes sure that a daemonwon't try to play with a disk drive when you aren't looking.Then you<ACLASS="indexterm"NAME="AUTOID-1369"></A>run a program named <EMCLASS="emphasis">sync</EM>, which makes sure that the disks havefinished doing everything. Only then is it safe to pull the switch.When you start up a UNIX system, it automatically runs a<ACLASS="indexterm"NAME="AUTOID-1372"></A>program called <EMCLASS="emphasis">fsck</EM>, which stands for &quot;filesystemcheck&quot;-its job is to find out if you shut down the systemcorrectly and fix any damage that might have happened if you didn't.</P><PCLASS="para">In this book, we will avoid administrative issues like <EMCLASS="emphasis">shutdown</EM>,<EMCLASS="emphasis">sync</EM>, and <EMCLASS="emphasis">fsck</EM>. But they provide good examples of howUNIX differs from simpler operating systems. If you understand whythese programs are needed, you are on your way to becoming a poweruser.</P><ACLASS="indexterm"NAME="AUTOID-1379"></A><ACLASS="indexterm"NAME="AUTOID-1380"></A><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN></P></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="ch01_13.htm"TITLE="1.13 Why Fundamentals Are Important "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 1.13 Why Fundamentals Are Important "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="ch01_15.htm"TITLE="1.15 Filenames "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 1.15 Filenames "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">1.13 Why Fundamentals Are Important </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">1.15 Filenames </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 + -