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

📄 ch42_02.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 42] 42.2 Fixing a Hung Terminal or Job </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:52:22Z"><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="ch42_01.htm"TITLE="42. Problems with Terminals"><LINKREL="prev"HREF="ch42_01.htm"TITLE="42.1 Making Sense Out of the Terminal Mess "><LINKREL="next"HREF="ch42_03.htm"TITLE="42.3 Why Changing TERM Sometimes Doesn't Work "></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="ch42_01.htm"TITLE="42.1 Making Sense Out of the Terminal Mess "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 42.1 Making Sense Out of the Terminal Mess "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 42<BR>Problems with Terminals</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch42_03.htm"TITLE="42.3 Why Changing TERM Sometimes Doesn't Work "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 42.3 Why Changing TERM Sometimes Doesn't Work "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-5250">42.2 Fixing a Hung Terminal or Job </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46572"></A><ACLASS="indexterm"NAME="AUTOID-46575"></A><ACLASS="indexterm"NAME="AUTOID-46578"></A>Here are a lot of techniques for unlocking alocked-up terminal or window session.</P><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-5250-SECT-1.1">42.2.1 Output Stopped? </A></H3><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46584"></A><ACLASS="indexterm"NAME="AUTOID-46586"></A>If your terminal has a HOLD SCREEN or SCROLL LOCK button, did youaccidentally press it?Try pressing it and see if things start working.If pressing the button once doesn't fix the problem, you should probably pressit once more to undo the screen hold.Otherwise, you may lock up your session worse than it was before!</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46589"></A><ACLASS="indexterm"NAME="AUTOID-46592"></A><ACLASS="indexterm"NAME="AUTOID-46595"></A>Another way to stop output is by pressing CTRL-s.The way to restart stopped output is with CTRL-q&nbsp;- trypressing that now.(Unlike aSCROLL&nbsp;LOCKbutton, though, if CTRL-qdoesn't help, you don't needto undo it.)</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-5250-SECT-1.2">42.2.2 Job Stopped? </A></H3><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46601"></A>If you have a<SPANCLASS="link">shell prompt (<ACLASS="linkend"HREF="ch07_01.htm#UPT-ART-4820"TITLE="Why Change Your Prompt? ">7.1</A>)</SPAN>instead of being in the program you thought youwere running&nbsp;- andif your UNIX has job control&nbsp;- you may have stopped a job.<SPANCLASS="link"> Try the <EMCLASS="emphasis">jobs</EM> command; if the job is stopped, restart it . (<ACLASS="linkend"HREF="ch12_08.htm"TITLE="Job Control in a Nutshell ">12.8</A>)</SPAN></P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-5250-SECT-1.3">42.2.3 Program Waiting for Input? </A></H3><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46609"></A>The program may be waiting for you to answer a question or type textto its standard input.</P><BLOCKQUOTECLASS="caution"><PCLASS="para"><STRONG>CAUTION:</STRONG> If the program you were running does something that's hard to undo-likeremoving files-<EMCLASS="emphasis">don't</EM> try this step unless you've thought about itcarefully.&#13;</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46616"></A><ACLASS="indexterm"NAME="AUTOID-46619"></A>If your system hasjob control,you can find out by putting the job in the background with CTRL-zand <EMCLASS="emphasis">bg</EM>.If the job was waiting for input, you'll see the message:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">[1]  + Stopped (tty input)  grep pat</PRE></BLOCKQUOTE></P><PCLASS="para">You canbring the job back into the foreground and answer its question,if you know what that question is.Otherwise, now that the job is stopped, you can kill it.See the following directions.</P><PCLASS="para">On systems without job control, you may be able to satisfy the program bypressing <KBDCLASS="keycap">[RETURN]</KBD>or some other key that the program is expecting, like <EMCLASS="emphasis">y</EM>or <EMCLASS="emphasis">n</EM>.You could also try pressing <KBDCLASS="keycap">[CTRL-d]</KBD> or whatever your &quot;end of input&quot; character is set to.That might log you out, though, unless you've set the<SPANCLASS="link"><EMCLASS="emphasis">ignoreeof</EM> variable (<ACLASS="linkend"HREF="ch03_05.htm"TITLE="Stop Accidental C Shell Logouts ">3.5</A>)</SPAN>.</P></BLOCKQUOTE></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-5250-SECT-1.4">42.2.4 Stalled Data Connection? </A></H3><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46636"></A><ACLASS="indexterm"NAME="AUTOID-46639"></A>If your terminal is hooked to a computer, modem, or network, be sure thatthe wires haven't come loose.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46642"></A><ACLASS="indexterm"NAME="AUTOID-46644"></A>If you're using a modem and the modem has function lights, try pressingkeys and see if the SD or Send Data light flashes.If it does, your terminal is sending data to the host computer.If the RD or Receive Data light flashes, the computer is sending data to yourterminal-if you don't see anything, there might be something wrong on yourterminal.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46647"></A><ACLASS="indexterm"NAME="AUTOID-46650"></A>If you're connected with<SPANCLASS="link"><EMCLASS="emphasis">rlogin</EM> or <EMCLASS="emphasis">telnet</EM> (<ACLASS="linkend"HREF="ch01_33.htm"TITLE="UNIX Networking and Communications ">1.33</A>)</SPAN>,the network to the remote computer might be down or be really slow.Try opening another connection to the same remote host-if you get a responselike <CODECLASS="literal">Connection</CODE> <CODECLASS="literal">timed</CODE> <CODECLASS="literal">out</CODE>, you have two choices:</P><OLCLASS="orderedlist"><LICLASS="listitem"><PCLASS="para">Wait for your original connection to unfreeze.The connection may come back and let you keep working where you left off.Or the connection may end when <EMCLASS="emphasis">rlogin</EM> or <EMCLASS="emphasis">telnet</EM> noticesthe network problem.</P></LI><LICLASS="listitem"><PCLASS="para">Quit the session and try later.</P></LI></OL></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-5250-SECT-1.5">42.2.5 Aborting Programs </A></H3><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46669"></A><ACLASS="indexterm"NAME="AUTOID-46672"></A><ACLASS="indexterm"NAME="AUTOID-46675"></A>To abort a program, most users press CTRL-c.Your account may be set up to use a different interruptcharacter, like DELETE or RUBOUT.If these don't work, try CTRL-/(CTRL-backslash).Under most circumstances, this will force the program to terminate.Otherwise, do the following:</P><OLCLASS="orderedlist"><LICLASS="listitem"><PCLASS="para">Log in at another terminal or window.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46682"></A>Enter the command <CODECLASS="literal">ps -x</CODE>.On System V, use <CODECLASS="literal">ps -u </CODE><CODECLASS="replaceable"><I>yourname</I></CODE>, where <CODECLASS="replaceable"><I>yourname</I></CODE>is your UNIX username.This displays a list of theprograms you are running, something like this:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>ps -x</B></CODE>PID     TTY     STAT    TIME    COMMAND163     i26     I       0:41    -csh (csh)8532    i26     TW      2:17    vi ts.ms22202   i26     S       12:50   vi UNIXintro.ms8963    pb      R       0:00    ps -x24077   pb      S       0:05    -bin/csh (csh)%</PRE></BLOCKQUOTE></P><PCLASS="para"></P></LI><LICLASS="listitem"><PCLASS="para">Search through this list to find the command that has backfired.Note the process identification (PID) number for this command.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46697"></A>Enter the command<SPANCLASS="link"><CODECLASS="literal">kill </CODE><CODECLASS="replaceable"><I>PID</I></CODE> (<ACLASS="linkend"HREF="ch38_10.htm"TITLE="Destroying Processes with kill ">38.10</A>)</SPAN>,where <EMCLASS="emphasis">PID</EM> is the identification number from the previous step.If that doesn't work, try <CODECLASS="literal">kill -1 </CODE><CODECLASS="replaceable"><I>PID</I></CODE> to send aHUP signal.You may need <EMCLASS="emphasis">kill -9</EM>, but try the other <EMCLASS="emphasis">kill</EM>s first.</P></LI><LICLASS="listitem"><PCLASS="para">If the UNIX shell prompt (like <CODECLASS="literal">%</CODE> or <CODECLASS="literal">$</CODE>)has appeared at youroriginal terminal, things are probably back to normal.You may still have to<SPANCLASS="link">  take the terminal out of a strange mode  (<ACLASS="linkend"HREF="ch42_04.htm"TITLE="Checklist for Resetting a Messed Up Terminal ">42.4</A>)</SPAN>though.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46714"></A><ACLASS="indexterm"NAME="AUTOID-46716"></A><ACLASS="indexterm"NAME="AUTOID-46718"></A>If the shell prompt hasn't come back, find the shell associated with your terminal (identified by a tty number) and <EMCLASS="emphasis">kill</EM> it.The command name for the C shell is <EMCLASS="emphasis">csh</EM>.For the Bourne shell, it is <EMCLASS="emphasis">sh</EM>.In most cases, this will destroy any other commands running from your terminal.Be sure to <EMCLASS="emphasis">kill</EM> the shell on your own terminal, not the terminal you borrowed to enter these commands. The tty you borrowed is the one running <EMCLASS="emphasis">ps</EM>; look atthe example above and check the <CODECLASS="literal">TTY</CODE> column.In this case, the borrowed terminal is TTYpb.</P><PCLASS="para">Check <EMCLASS="emphasis">ps</EM> to ensure that your shell has died.If it is still there, take more drastic action with the command <CODECLASS="literal">kill -9 </CODE><CODECLASS="replaceable"><I>PID</I></CODE>.</P></LI><LICLASS="listitem"><PCLASS="para">Run <EMCLASS="emphasis">ps -x</EM> again to be sure that all processes on the other ttyhave died.(In some cases, processes will remain.)If there are still processes on the other tty, kill them.</P></LI><LICLASS="listitem"><PCLASS="para">At this point, you should be able to log in again from your own terminal.</P></LI></OL><PCLASS="para">The<SPANCLASS="link"><EMCLASS="emphasis">ps</EM> (<ACLASS="linkend"HREF="ch38_05.htm"TITLE="The ps Command ">38.5</A>)</SPAN>command,which lists all the programs you are running, also gives you useful information about the status of each program and the amount of CPU time it has consumed.Note that <EMCLASS="emphasis">ps</EM> lists all the programs you are running, including programs you maynot know about (e.g., programs that other programs execute automatically).</P></DIV><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</SPAN>, <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="ch42_01.htm"TITLE="42.1 Making Sense Out of the Terminal Mess "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 42.1 Making Sense Out of the Terminal Mess "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="ch42_03.htm"TITLE="42.3 Why Changing TERM Sometimes Doesn't Work "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 42.3 Why Changing TERM Sometimes Doesn't Work "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">42.1 Making Sense Out of the Terminal Mess </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">42.3 Why Changing TERM Sometimes Doesn't Work </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 + -