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

📄 143-145.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Linux Unleashed, Third Edition:Basic Linux Commands</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=7//-->

<!--PAGES=143-145//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="141-143.html">Previous</A></TD>

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

<TD><A HREF="145-148.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H4 ALIGN="LEFT"><A NAME="Heading16"></A><FONT COLOR="#000077">The Process Termination Command: kill</FONT></H4>

<P>Although these processes are usually well-behaved and well-managed by Linux, sometimes they may go out of control. This can happen if a program hits a bug or a flaw in its internal code or supplied data or if you accidentally enter the wrong command or command option.

</P>

<P>Being able to identify these errant processes and then being able to terminate or <I>kill</I> them is an essential piece of knowledge for <I>all</I> Linux users. (Obviously, the world was a less kind and gentle place when the <TT><B>kill</B></TT> command was developed and named.) When you are your own system administrator, as in our case, it&#146;s doubly important to be able to kill processes that have gone awry or locked up!</P>

<P>The <TT><B>kill</B></TT> command is used to terminate processes that can&#146;t be stopped by other means.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>Note:&nbsp;&nbsp;</B><BR>Before going through the following procedure, if it&#146;s a program that you&#146;re stuck in, make sure you can&#146;t stop or exit it by pressing Ctrl&#43;C or some other key combination like <TT><B>q</B></TT>.<HR></FONT>

</BLOCKQUOTE>

<DL>

<DD><B>1.</B>&nbsp;&nbsp;Switch to another virtual console and log in as <TT><B>root</B></TT>.

<DD><B>2.</B>&nbsp;&nbsp;Run <TT><B>ps -u</B></TT> and identify the offending process. Note the process ID (PID) number for that process. You will use its PID in the next step.

<DD><B>3.</B>&nbsp;&nbsp;Use the <TT><B>kill</B></TT> program by typing <TT><B>kill &lt;<I>PID</I>&gt;</B></TT>, where <I>PID</I> is the Process ID you want to kill. Make sure that you have correctly identified the offending process! As <TT><B>root</B></TT>, you can kill any user process, including the wrong one if you misread or mistype the PID.

<DD><B>4.</B>&nbsp;&nbsp;Verify that the process has been killed by using <TT><B>ps -u</B></TT> again. You can type <TT><B>ps -u</B></TT> <TT><B>&lt;<I>PID</I>&gt;</B></TT>, which shows you the status of only the specified PID. If there&#146;s a null result and you&#146;re just given the Linux prompt again, the PID is dead, so go to step 8. However, it&#146;s best to look at the complete <TT><B>ps -u</B></TT> list if it&#146;s not too long. Sometimes the offending process reappears with a new PID! If that is the case, go to step 6.

<DD><B>5.</B>&nbsp;&nbsp;If the process is still alive and has the same PID, use <TT><B>kill</B></TT>&#146;s <TT><B>9</B></TT> option. Type <TT><B>kill -9</B></TT> <TT><B>&lt;<I>PID</I>&gt;</B></TT>. Check it in the same way as in step 4. If this does not kill the process, go to step 7. If the process is now dead, go to step 8.

<DD><B>6.</B>&nbsp;&nbsp;If the offending process has reappeared with a new PID, that means that it&#146;s being created automatically by some other process. The only thing to do now is to kill the parent process, which is the true offender! You may also have to kill the parent process when <TT><B>kill -9</B></TT> does not work.

<DD><B>7.</B>&nbsp;&nbsp;Use <TT><B>ps -l</B></TT> to identify the troublesome process&#146;s PPID. This is the PID of the parent process. You should check the parent&#146;s identity more closely by typing <TT><B>ps -u</B></TT> <TT><B>&lt;<I>Parent PID</I>&gt;</B></TT> before going ahead and killing it as described in step 3, using the PID of the <I>parent</I> in the <TT><B>kill</B></TT> command. You should follow through with step 4 and, if necessary, step 5, making sure the parent process has been killed.

<DD><B>8.</B>&nbsp;&nbsp;The process is killed. Remember to log off. Do not leave <TT><B>root</B></TT> logged in on virtual consoles because you may forget that the <TT><B>root</B></TT> logins are there.

</DL>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>Note:&nbsp;&nbsp;</B><BR>Sometimes processes are simply unkillable! In this case, your best bet is shutting down the Linux system and rebooting.<HR></FONT>

</BLOCKQUOTE>

<P>Linux keeps ordinary users (as opposed to <TT><B>root</B></TT>) from killing other users&#146; processes (maliciously or otherwise). For instance, if you are an ordinary user and try to kill the <TT><B>init</B></TT> process, which always has PID=1, you will see a message similar to this one:</P>

<!-- CODE SNIP //-->

<PRE>

darkstar:~&#36; <TT><B>kill 1</B></TT>

kill: (1) - Not owner

</PRE>

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

<P>Actually, not even <TT><B>root</B></TT> can kill the <TT><B>init</B></TT> process, although there is no error message. The <TT><B>init</B></TT> process is one of those &#147;unkillable&#148; processes discussed earlier because it&#146;s such a key process. That&#146;s all for the best!</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="141-143.html">Previous</A></TD>

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

<TD><A HREF="145-148.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 + -