UNIX For Dummies [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

UNIX For Dummies [Electronic resources] - نسخه متنی

John Levine, Margaret Levine Young

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید






Dirty Deeds, Done Dirt Cheap

No more Mister Nice Guy: It’s time for merciless slaughter. If you were successful in the preceding section at putting the process to sleep with Ctrl+Z, go ahead and kill it with the procedure in this section.

All the following techniques require that you have a terminal or window in which you can type some commands to do the dirty deeds. If Ctrl+Z didn’t work to put the process to sleep, you may not have a shell prompt at which to type the requisite commands. Here are other places you can use to type the commands to kill the process:



If you’re running X Windows, any window other than the one with the stuck program works.



Otherwise, you may have to go to another computer on the network and use telnet or ssh to get into your computer.



If no other window is available and you have no other way into the machine, you’re out of luck and probably have to reboot. Before you reboot, check with your system administrator, who may know some other tricks.



This simple two-step procedure murders a rogue process:



Find out the rogue process’s true name.


Utter the true name in an appropriate spell to murder it.


The true name of a process is its PID, one of the things ps reports. First do a ps command to find out the PID of your victim. To find out the PID, follow these steps:



If you pressed Ctrl+Z to put the rogue process to sleep and you’re using the same terminal to kill it utterly, type a plain ps.
Linux Otherwise, you may have to use a different terminal to kill the process because the amok process has taken over your own terminal.


In this case, you have to tell ps which user’s processes you want to see.
If you use Linux, type this command:


ps -u username

Replace username with your own login name so that you see the processes you’re running.

If you use System V, type this command:


ps -fu username

If you use BSD, type
ps -a



Suppose that you see the following listing after typing ps -fu johnl , which lists all the processes for user johnl (the listing is shortened to save space):

UID PID PPID C STIME TTY TIME COMMAND
johnl 24806 24799 0 Jan 18 ? 0:39 xclock
The PID of the process you want to kill is 24806. You kill it by typing the kill command:


kill 24806









Tip Resuscitating a terminal


If you blow away a program that reads a character at a time from your terminal, such as vi or emacs , the dead process leaves your terminal in a rather peculiar state that makes getting any work done hard. The following three-step method usually brings the terminal back:



Press Ctrl+J.


The shell may complain about strangely named nonexistent commands. Ignore its whining.



Type stty , a space, and sane (as opposed to the insane state your terminal is in). Press Enter.



You may not see anything on-screen. Remain calm.



Press Ctrl+J again.


This step puts your terminal back into a usable state.












The normal type of kill sends a request to a process: "Please, nice Mr. Process, would you be so kind as to croak?" Although this method usually works, occasionally a program doesn’t take the hint. Another kind of kill , the ominously named Number-Nine kill , offers the victim no choice. Type this command:


kill -9 24806

If you stop a particularly uncooperative program with Ctrl+Z, a regular kill may provoke it to retaliate by trying to take over your terminal (something the shell, fortunately, prevents). The following example shows a true-life transcript of our attempts to murder our old text editor pal, ed . First, we pressed Ctrl+Z, which put it to sleep. Then we tried a regular kill . When ed tried to strike back, we did a Number Nine. Sayonara, Bud.

% ed badfile
?badfile
Ctrl-Z
Stopped
% ps
PID TTY TIME COMMAND
12746 ttyp1 0:00 ed
12747 ttyp1 0:00 ps
11643 ttyp1 0:02 -csh
% kill 12746
?
[1] + Stopped (tty input) ed badfile
% kill -9 12746
[1] Killed ed badfile

/ 213