📄 586-589.html
字号:
<HTML>
<HEAD>
<TITLE>Using Linux:Managing the Kernel</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=0789716232//-->
<!--TITLE=Using Linux//-->
<!--AUTHOR=William Ball//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Que//-->
<!--CHAPTER=32//-->
<!--PAGES=586-589//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="583-586.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="589-592.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading17"></A><FONT COLOR="#000077">Using the <I>kill</I> Command and Process IDs
</FONT></H4>
<P>The <TT>kill</TT> utility is used to send signals to processes. One of the uses, as the name of the utility suggests, is for terminating or removing unwanted processes from the system. <TT>kill</TT> can also send other signals to processes. For instance, the <TT>HUP</TT> signal by convention causes most daemon programs to re-read their initialization files.</P>
<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD><FONT SIZE="+1"><B>Confusing signal names</B></FONT>
<BR>Signal names such as <TT><B>HUP</B></TT> and <TT><B>KILL</B></TT> are often referred to as <TT><B>SIGHUP</B></TT> and <TT><B>SIGKILL</B></TT>. Either way of writing them is usually valid, but some utilities might accept only one or the other.</TABLE>
<P>Another noteworthy point is that most shells, such as <TT>bash</TT>, contain their own built-in <TT>kill</TT> utilities. On some shells, this can be quite different than the <TT>kill</TT> that’s described here, and you’d do well to check your shell’s documentation to see how that behaves. In this section, you learn about <TT>bash</TT>’s <TT>kill</TT> behavior.</P>
<P>The <TT>bash</TT> shell is capable of getting a process ID for you, provided the process is running in the background of that session. For other processes, you must use the <TT>ps</TT> utility to get the process ID. You can kill only processes that your user ID owns—unless, of course, you are logged on as root.</P>
<P>This syntax of the <TT>kill</TT> command is as follows:</P>
<!-- CODE SNIP //-->
<PRE>
kill -s <signal> <process id>
</PRE>
<!-- END CODE SNIP //-->
<P>To print a list of signals and their numbers, execute the following command:
</P>
<!-- CODE SNIP //-->
<PRE>
<B>kill -l</B>
</PRE>
<!-- END CODE SNIP //-->
<P>The default signal that <TT>kill</TT> sends is <TT>TERM</TT> signal.</P>
<P><FONT SIZE="+1"><B><I>Killing a process</I></B></FONT></P>
<DL>
<DD><B>1.</B> Obtain the process ID by running <TT>ps</TT>. If the list is too long, and if you know the process name, try piping the output to the <TT>grep</TT> utility to find the word for you.
<DD><B>2.</B> With the process ID handy, type the command <TT>kill <PID></TT>, where <TT><PID></TT> is the process ID number. The command prompt returns. If <TT>bash</TT> complains about there being no such process, then you have the wrong number, or the process has already terminated.
<DD><B>3.</B> After the next command is executed, <TT>bash</TT> should produce a message such as the following:
<!-- CODE SNIP //-->
<PRE>
[1]+ Terminated find / -name what
</PRE>
<!-- END CODE SNIP //-->
<BR>If it does not produce such a message, the process is not responding to <TT>TERM</TT> signals. In this example, the program <TT>find</TT> was terminated.
<DD><B>4.</B> If <TT>bash</TT> does not issue that message, and another look using <TT>ps</TT> shows that the process is still merrily gobbling up your CPU time, you’ll need to do something more drastic. First make sure that the program is not doing some sort of shutdown processing that needs to be completed, and then issue the following command to kill the process:
<!-- CODE SNIP //-->
<PRE>
kill –s 9 <PID>
</PRE>
<!-- END CODE SNIP //-->
<BR>This is a signal that a program cannot ignore, so the process is terminated even if it does not want to be. After the next command (or just after pressing Enter if you have nothing else to do), <TT>bash</TT> should print the following message to tell you that the program has been killed:
<!-- CODE SNIP //-->
<PRE>
[1]+ Killed find / -name what
</PRE>
<!-- END CODE SNIP //-->
</DL>
<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD><FONT SIZE="+1"><B>Getting impatient when sending signals to programs</B></FONT>
<BR>Some programs need to do some work before shutting down, such as saving open files. Be sure to give the program enough time to do this, or data loss can occur.</TABLE>
<H3><A NAME="Heading18"></A><FONT COLOR="#000077">Recompiling the Kernel</FONT></H3>
<P>Every once in a while, it is worthwhile to see whether a new kernel for Linux has been released. Usually new kernels provide fixes for problems that people have experienced, or provide performance improvements (usually both). The new kernels can also contain more device drivers. This section discusses how to obtain, compile, and install a new kernel on your Linux system.
</P>
<P>The official repository for Linux kernels is the FTP site <TT>sunsite.unc.edu</TT>, in the directory <TT>/pub/Linux/kernel/v2.0</TT>. The Red Hat Linux installation program should have placed the source code to your current kernel in the <TT>/usr/src/linux</TT> directory on your hard disk. This is a symbolic link to the actual source directory.</P>
<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD><FONT SIZE="+1"><B>The disclaimer</B></FONT>
<BR>The process of compiling and installing kernels is not for the technically faint-of-heart: Mistakes here could leave your system in an unbootable state, or worse, could damage your hardware or disk contents. You have been warned.</TABLE>
<H4 ALIGN="LEFT"><A NAME="Heading19"></A><FONT COLOR="#000077">Installing the New Kernel Source</FONT></H4>
<P>After you have downloaded the kernel source, you must decompress it and extract the directories within. You must be logged on as root, as well, or at least have full permissions to the <TT>/usr/src</TT> directory. This assumes that you have downloaded the kernel source to the <TT>/root</TT> directory. Be sure to substitute the directory that the kernel was downloaded to for your system. You must also have about 10–15 MB of free space to extract and compile a new kernel.</P>
<DL>
<DD><B>1.</B> Delete the symbolic link pointing to the current Linux kernel source directory. The idea is to avoid overwriting the current source directory, because it might contain modifications you have made. It’s also a setup that you should be able to restore if something goes wrong. The command is as follows:
<!-- CODE SNIP //-->
<PRE>
<B>rm linux</B>
</PRE>
<!-- END CODE SNIP //-->
<BR>If <TT>rm</TT> tells you you’re deleting a directory, then there is something wrong. Check the directory you’re in, and make sure that <TT>linux</TT> is a symbolic link to the current source directory.
<DD><B>2.</B> Create the new directory to hold the kernel source. The reason this is being done is that the source distribution wants to extract itself to a directory called <TT>linux</TT>, but this is not the way it is intended to be used. Create a directory with an appropriate name, usually <TT>linux-</TT>, followed by the kernel version (for example, <TT>linux-2.0.33</TT>).
<DD><B>3.</B> Create the new symbolic link to the new directory by entering the following:
<!-- CODE SNIP //-->
<PRE>
<B>ln -s <your directory name> linux</B>
</PRE>
<!-- END CODE SNIP //-->
<DD><B>4.</B> Extract the file to the new directory by entering the following:
<!-- CODE SNIP //-->
<PRE>
<B>tar xzvf <kernel file name></B>
</PRE>
<!-- END CODE SNIP //-->
<BR>Your new kernel source is now correctly installed and you can configure the kernel. Depending on the speed of your system, this can take some time.
</DL>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="583-586.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="589-592.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -