Merge pull request #2852 from geekpi/master

translated
This commit is contained in:
geekpi 2015-05-30 10:51:35 +08:00
commit 700ab3229d
2 changed files with 93 additions and 94 deletions

View File

@ -1,94 +0,0 @@
translating---geekpi
How to Kill Linux Processes/Unresponsive Applications Using xkill Command
================================================================================
How do we kill a resource/process in Linux? Obviously we find the PID of the resource and then pass the PID to the kill command.
Speaking more accurately, we can find PID of a resource (say terminal) as:
$ ps -A | grep -i terminal
6228 ? 00:00:00 gnome-terminal
In the above output, the number 6228 is the PID of process (gnome-terminal), use the kill command to kill the process as shown below.
$ kill 6228
The kill command sends a signal to a process, whose PID is passed along with the command.
Alternatively, we can use pkill command, which kills a process based upon name and other attributes of a process. To kill a process say whose name is terminal, we need to execute:
$ pkill terminal
**Note**: The process name length in pkill is limited to 15 characters.
pkill seems more handy as you can kill a process without have to find out its PID. But if you want to have a better control on your system nothing beats kill command. Using kill you will have better insight of what process you are killing.
We have already covered a detailed guide on [kill, pkill and killall commands][1].
For those who are running X server there is another tool called xkill which can kill a process from its X window without passing process name or its PID.
xkill utility forces X server to close communications to its client which results into killing of client by its X resource. xkill which is a part of X11 utilities is very handy in killing unnecessary windows.
It support options like connect to specific X Server (-display displayname) using display number when multiple X Servers are running on a host simultaneously and kill all the client (-all, not recommended) with top-level windows on the screen as well as take frame (-frame) into account.
To get a list of all the clients you may run:
$ xlsclients
#### Sample Output ####
' ' /usr/lib/libreoffice/program/soffice
deb gnome-shell
deb Docky
deb google-chrome-stable
deb soffice
deb gnome-settings-daemon
deb gnome-terminal-server
If no resource identifier is passed with id, xkill turns the mouse Pointer into special Symbol, similar to X. Just click on the window you want to kill and this will kill its communication with server or say the program gets killed.
$ xkill
![Xkill Command](http://www.tecmint.com/wp-content/uploads/2015/05/Xkill.png)
Kill Process Using xkill
It is important to notice that xkill do not guarantee that closing its communication will kill/abort it successfully. Most of the application will get killed when its communication to server is closed. However a few may still be running.
Points Needed to be mentioned here:
- This tool works only when X11 server is running, as xkill is a part of X11 utility.
- Dont confuse with Closing and killing a resource. While killing a resource you may expect it not to exit cleanly.
- This is not a replacement of kill utility.
**Do I need to go to Linux command line to invoke xkill?**
No, you dont need to fire xkill from Linux Command Line. You may set a keyboard shortcut and call xkill just by punching same key combination.
Here is how to setup a keyboard shortcut on a typical gnome3 Desktop Environment.
Go to Settings > Select Keyboard, click on + and add name and command. Click on the new entry and press the key you want to use as shortcut key combination. I did Ctrl+Alt+Shift+x.
![Gnome Settings](http://www.tecmint.com/wp-content/uploads/2015/05/22.png)
Gnome Settings
![Add Shortcut Key](http://www.tecmint.com/wp-content/uploads/2015/05/31.png)
Add Shortcut Key
The next time you want to kill a X resource just call the key combination (Ctrl+Alt+Shift+x), and you will notice your mouse pointer changed into x. Click on x resource you want to kill and all done!
--------------------------------------------------------------------------------
via: http://www.tecmint.com/kill-processes-unresponsive-programs-in-ubuntu/
作者:[Avishek Kumar][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/avishek/
[1]:http://www.tecmint.com/how-to-kill-a-process-in-linux/

View File

@ -0,0 +1,93 @@
如何使用xkill命令傻点Linux进程/未响应的程序
================================================================================
我们如何在Linux中杀掉一个资源/进程很明显我们会找出资源的pid然后用kill命令。
更准确一点我们可以找到资源这里就是terminal的PID
$ ps -A | grep -i terminal
6228 ? 00:00:00 gnome-terminal
上面的输出中6288就是进程gnome-terminal的pid 使用下面的命令来杀掉进程。
$ kill 6228
kill命令会发送一个信号给该pid的进程。
另外一个方法是我们可以使用pkill命令,它可以基于进程的名字或者其他的属性来杀掉进程。同样我们要杀掉一个叫terminal的进程可以这么做
$ pkill terminal
**注意**: pkill命令后面进程名的长度不大于15个字符
pkill看上去更加容易上手因为你你不用找出进程的pid。但是如果你要对系统做更好的控制那么没有什么可以打败'kill'。使用kill命令可以更好地审视你要杀掉的进程。
我们已经有一篇覆盖了[kill、pkill和killall命令][1]间细节的指导了。
对于那些运行X Server的人而言有另外一个工具称为xkill可以将进程从X Window中杀掉而不必传递它的名字或者pid。
xkill工具强制X server关闭于它客户端之间的联系这可以让X resource关闭这个客户端。xkill是X11工具集中一个非常容易上手的杀掉无用窗口的工具。
它支持的选项如在同时运行多个X Server时使用-display选项后面跟上显示号连接到指定的X server使用-all(并不建议)杀掉所有在屏幕上的所遇顶层窗口,同时将帧(-frame也计算在内。
要得到所有的客户端你可以运行:
$ xlsclients
#### 示例输出 ####
' ' /usr/lib/libreoffice/program/soffice
deb gnome-shell
deb Docky
deb google-chrome-stable
deb soffice
deb gnome-settings-daemon
deb gnome-terminal-server
如果后面没有跟上资源idxkill会将鼠标指针变成一个特殊符号类似于“X”。只需在你要杀掉的窗口上点击它就会杀掉它与server端的通信这个程序就被杀掉了。
$ xkill
![Xkill Command](http://www.tecmint.com/wp-content/uploads/2015/05/Xkill.png)
使用xkill杀掉进程
需要注意的是xkill并不能保证它的通信会被成功杀掉/退出。大多数程序会在与服务端的通信被关闭后杀掉。然而仍有少部分会继续运行。
需要指出的点是:
- 这个工具只能在X11 server运行的时候才能使用因为这是X11工具的一部分。
- 不要在你杀掉一个资源而它没有完全退出时而困惑。
- 这不是kill的替代品
**我需要在linux命令行中使用xkill么**
不是你不必在命令行中运行xkill。你可以设置一个快捷键并用它来调用xkill。
下面是如何在典型的gnome3桌面中设置键盘快捷键。
进入设置-> 选择键盘。点击'+'并添加一个名字和命令。点击点击新条目并按下你想要的组合键。我的是Ctrl+Alt+Shift+x。
![Gnome Settings](http://www.tecmint.com/wp-content/uploads/2015/05/22.png)
Gnome 设置
![Add Shortcut Key](http://www.tecmint.com/wp-content/uploads/2015/05/31.png)
添加快捷键
下次你要杀掉X资源只要用组合键就行了Ctrl+Alt+Shift+x你看到你的鼠标变成x了。点击想要杀掉的x资源就行了。
--------------------------------------------------------------------------------
via: http://www.tecmint.com/kill-processes-unresponsive-programs-in-ubuntu/
作者:[Avishek Kumar][a]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/avishek/
[1]:http://www.tecmint.com/how-to-kill-a-process-in-linux/