mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
翻译完成Mastering\ the\ “Kill”\ Command\ in\ Linux.md
This commit is contained in:
parent
860efa84f1
commit
27df03b09e
@ -1,89 +0,0 @@
|
||||
翻译中
|
||||
Mastering the “Kill” Command in Linux
|
||||
================================================================================
|
||||
It doesn’t matter which operating system you are using, you will surely come across a misbehaving application that lock itself up and refuse to close. In Linux (and Mac), there is this “kill” command that you can use to terminate the application forcefully. In this tutorial, we will show you the various way you can make use of the “kill” command to terminate an application.
|
||||
|
||||
**Kill Commands and Signals**
|
||||
|
||||
When you execute a “kill” command, you are in fact sending a signal to the system to instruct it to terminate the misbehaving app. There is a total of 60 signals that you can use, but all you really need to know is SIGTERM (15) and SIGKILL (9).
|
||||
|
||||
You can view all the signals with the command:
|
||||
|
||||
kill -l
|
||||
|
||||
![](http://i1.wp.com/imagecdn5.maketecheasier.com/2013/10/kill-list-signal.png)
|
||||
|
||||
- SIGTERM – This signal requests a process to stop running. This signal can be ignored. The process is given time to gracefully shutdown. When a program gracefully shuts down, that means it is given time to save its progress and release resources. In other words, it is not forced to stop.
|
||||
- SIGKILL – The SIGKILL signal forces the process to stop executing immediately. The program cannot ignore this signal. Unsaved progress will be lost.
|
||||
|
||||
The syntax for using “kill” is:
|
||||
|
||||
kill [signal or option] PID(s)
|
||||
|
||||
The default signal (when none is specified) is SIGTERM. When that doesn’t work, you can use the following to kill a process forcefully:
|
||||
|
||||
kill SIGKILL PID
|
||||
|
||||
or
|
||||
|
||||
kill -9 PID
|
||||
|
||||
where the “-9” flag refers to SIGKILL signal.
|
||||
|
||||
If you are not aware of the PID of the application, simply run the command:
|
||||
|
||||
ps ux
|
||||
|
||||
and it will display all the running applications together with its PID.
|
||||
|
||||
![](http://i1.wp.com/imagecdn5.maketecheasier.com/2013/10/kill-find-pid.png)
|
||||
|
||||
For example, to kill the Chrome app, I will run the command:
|
||||
|
||||
kill -9 3629
|
||||
|
||||
Do also note that you can kill multiple processes at the same time.
|
||||
|
||||
kill -9 PID1 PID2 PID 3
|
||||
|
||||
**PKill**
|
||||
|
||||
The “pkill” command allows the use of extended regular expression patterns and other matching criteria. Instead of using PID, you can now kill application by entering their process name. For example, to kill Firefox browser, just run the command:
|
||||
|
||||
pkill firefox
|
||||
|
||||
As it matches regular expression pattern, you can also enter partial name of the process, such as:
|
||||
|
||||
pkill fire
|
||||
|
||||
To avoid killing the wrong processes, you might want to do a “pgrep -l [process name]” to list the matching processes.
|
||||
|
||||
![](http://i0.wp.com/imagecdn5.maketecheasier.com/2013/10/kill-pgrep-command.png)
|
||||
|
||||
**Killall**
|
||||
|
||||
Killall uses the process name as well instead of PID, and it kills all instance of the process with the same name. For example, if you are running multiple instances of Firefox browser, you can kill them all with the command:
|
||||
|
||||
killall firefox
|
||||
|
||||
In Gnome, you can restart Nautilus by using the command:
|
||||
|
||||
killall nautilus
|
||||
|
||||
**xkill**
|
||||
|
||||
Xkill is a graphical way to kill an application. When you type “xkill” in the terminal, your mouse cursor will instantly become a “cross”. All you have to do is to click the “cross” at the misbehaving app and it will kill the application instantly. If you are keen, you can also add a [keyboard shortcut to activate the xkill][1] function.
|
||||
|
||||
**Conclusion**
|
||||
|
||||
When apps misbehave and cause the system to hang, it is very tempting to restart the computer and start the session all over again. With these “kill” commands, you will be able to better manage the misbehaving apps without them causing the system to crash. This is especially useful for a server when you don’t want a misbehaving process to bring the whole server down.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.maketecheasier.com/kill-command-in-linux/
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
[1]:http://www.maketecheasier.com/quick-tips/kill-unresponsive-application-in-ubuntu/
|
88
translated/Mastering the “Kill” Command in Linux.md
Normal file
88
translated/Mastering the “Kill” Command in Linux.md
Normal file
@ -0,0 +1,88 @@
|
||||
精通Linux "kill"命令
|
||||
================================================================================
|
||||
你使用哪种操作系统没有关系,你一定会遇到某个行为失常的应用,它把自己锁起来拒绝关闭.在Linux(还有Mac), 你可以用一个"kill"命令强制终结它.在这个教程中,我们将展示给你多种方式使用"kill"命令终结应用.
|
||||
|
||||
**Kill命令和信号**
|
||||
|
||||
当你执行一个"kill"命令,你实际上发送了一个信号给从左系统指示它终结不正常的应用.总共有60个你可一使用的信号,但是基本上你只需要知道SIGTERM(15)和SIGKILL(9).
|
||||
|
||||
你可以用这个命令看到所有的信号:
|
||||
|
||||
kill -l
|
||||
|
||||
![](http://i1.wp.com/imagecdn5.maketecheasier.com/2013/10/kill-list-signal.png)
|
||||
|
||||
- SIGTERM - 此信号请求一个进程停止运行.此信号是可以被忽略.进程被给一段时间正常关闭.一个程序正常关闭意味着给一段时间来保存进度并释放资源.换句话说,它不是强制停止
|
||||
- SIGKILL - 此个信号强制进程立刻停止运行.程序不能忽略此信号.未保存进度将丢失.
|
||||
|
||||
使用"kill"的语法是:
|
||||
|
||||
kill [信号或选项] PID(s)
|
||||
|
||||
默认信号(当没有指定的时候)是SIGTERM.当它不起作用时,你可以使用下面的命令来强制kill掉一个进程:
|
||||
|
||||
kill SIGKILL PID
|
||||
|
||||
or
|
||||
|
||||
kill -9 PID
|
||||
|
||||
这里"-9"引用SIGKILL信号.
|
||||
|
||||
如果你不知道应用的PID,仅需要运行这个命令:
|
||||
|
||||
ps ux
|
||||
|
||||
它会显示所有正在运行的应用还有应用的PID.
|
||||
|
||||
![](http://i1.wp.com/imagecdn5.maketecheasier.com/2013/10/kill-find-pid.png)
|
||||
|
||||
例如,要kill掉Chrome,我会运行命令:
|
||||
|
||||
kill -9 3629
|
||||
|
||||
也可以在同一时间kill多个进程.
|
||||
|
||||
kill -9 PID1 PID2 PID 3
|
||||
|
||||
**PKill**
|
||||
|
||||
"pkill"命令允许使用扩展的正则表达式和其它匹配标准.你现在可以使用应用的进程名kill掉它们,取代了使用PID.例如,kill Firefox浏览器,只需要运行命令:
|
||||
|
||||
pkill firefox
|
||||
|
||||
匹配正则表达式,你可以输入部分进程名,比如:
|
||||
|
||||
pkill fire
|
||||
|
||||
为了避免kill掉错误的进程,你应该用一下"pgrep -l [进程名]"列表来匹配进程.
|
||||
|
||||
![](http://i0.wp.com/imagecdn5.maketecheasier.com/2013/10/kill-pgrep-command.png)
|
||||
|
||||
**Killall**
|
||||
|
||||
killall同样使用进程名替代PID,并且它会kill掉所有的同名进程.例如,如果你正在运行多个Firefox浏览器的instances(实例),可以用命令把它们全部kill掉:
|
||||
|
||||
killall firefox
|
||||
|
||||
在Gnome,你可以重启Nautilus,使用这个命令:
|
||||
|
||||
killall nautilus
|
||||
|
||||
**xkill**
|
||||
|
||||
xkill 是图形方式kill一个应用.当你在终端键入"xkill",你的光标将立刻变成一个"十字".你必须在失常的应用上点击一下,它就会立刻kill掉这个应用.如果你喜欢精简,你也可以添加一个[键盘快捷键来激活xkill][1].
|
||||
|
||||
**结论**
|
||||
|
||||
当app失常导致系统挂起的时候,它非常有诱惑力相比于重启计算机并且再一次开启所有的会话.有了这些"kill"命令,你将能够更好的管理失常的应用避免导致系统崩溃.当你不想一个失常的进程带来服务器荡机时,它尤其的有用.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.maketecheasier.com/kill-command-in-linux/
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
译者:[flsf](https://github.com/flsf) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
[1]:http://www.maketecheasier.com/quick-tips/kill-unresponsive-application-in-ubuntu/
|
Loading…
Reference in New Issue
Block a user