linux进程管理类命令_如何从Linux终端管理进程:您需要知道的10个命令

linux进程管理类命令_如何从Linux终端管理进程:您需要知道的10个命令

linux进程管理类命令

linux进程管理类命令_如何从Linux终端管理进程:您需要知道的10个命令

The Linux terminal has a number of useful commands that can display running processes, kill them, and change their priority level. This post lists the classic, traditional commands, as well as some more useful, modern ones.

Linux终端具有许多有用的命令,这些命令可以显示正在运行的进程,将其杀死,并更改其优先级。 这篇文章列出了经典的传统命令,以及一些更有用的现代命令。

Many of the commands here perform a single function and can be combined — that’s the Unix philosophy of designing programs. Other programs, like htop, provide a friendly interface on top of the commands.

这里的许多命令执行一个功能,并且可以组合使用-这就是设计程序的Unix理念。 其他程序,例如htop,在命令之上提供了一个友好的界面。

最佳 (top)

The top command is the traditional way to view your system’s resource usage and see the processes that are taking up the most system resources. Top displays a list of processes, with the ones using the most CPU at the top.

top命令是查看系统资源使用情况并查看占用最多系统资源的进程的传统方式。 “顶部”显示进程列表,其中使用CPU最多的进程位于顶部。

linux进程管理类命令_如何从Linux终端管理进程:您需要知道的10个命令

To exit top or htop, use the Ctrl-C keyboard shortcut. This keyboard shortcut usually kills the currently running process in the terminal.

要退出top或htop,请使用Ctrl-C键盘快捷键。 此键盘快捷键通常会终止终端中当前正在运行的进程。

停止 (htop)

The htop command is an improved top. It’s not installed by default on most Linux distributions — here’s the command you’ll need to install it on Ubuntu:

htop命令是改进的top。 在大多数Linux发行版中,默认情况下未安装它-这是在Ubuntu上安装它所需要的命令:

sudo apt-get install htop

sudo apt-get install htop

linux进程管理类命令_如何从Linux终端管理进程:您需要知道的10个命令

htop displays the same information with an easier-to-understand layout. It also lets you select processes with the arrow keys and perform actions, such as killing them or changing their priority, with the F keys.

htop以更易于理解的布局显示相同的信息。 它还使您可以使用箭头键选择进程并使用F键执行操作,例如杀死它们或更改其优先级。

We’ve covered htop in more detail in the past.

过去,我们已经详细介绍了htop

ps (ps)

The ps command lists running processes. The following command lists all processes running on your system:

ps命令列出了正在运行的进程。 以下命令列出了系统上运行的所有进程:

ps -A

ps -A

linux进程管理类命令_如何从Linux终端管理进程:您需要知道的10个命令

This may be too many processes to read at one time, so you can pipe the output through the less command to scroll through them at your own pace:

可能一次要读取的进程太多,因此您可以通过less命令通过管道传递输出,以您自己的步调滚动它们:

ps -A | less

ps -A | 减

Press q to exit when you’re done.

完成后,按q退出。

You could also pipe the output through grep to search for a specific process without using any other commands. The following command would search for the Firefox process:

您也可以通过grep通过输出管道搜索特定进程,而无需使用任何其他命令。 以下命令将搜索Firefox进程:

ps -A | grep firefox

ps -A | grep Firefox

linux进程管理类命令_如何从Linux终端管理进程:您需要知道的10个命令

pstree (pstree)

The pstree command is another way of visualizing processes. It displays them in tree format. So, for example, your X server and graphical environment would appear under the display manager that spawned them.

pstree命令是可视化过程的另一种方式。 它以树格式显示它们。 因此,例如,您的X服务器和图形环境将出现在生成它们的显示管理器下。

linux进程管理类命令_如何从Linux终端管理进程:您需要知道的10个命令

(kill)

The kill command can kill a process, given its process ID. You can get this information from the ps -A, top or pgrep commands.

给定进程ID, kill命令可以杀死该进程。 您可以从ps -Atoppgrep命令获得此信息。

kill PID

杀死PID

linux进程管理类命令_如何从Linux终端管理进程:您需要知道的10个命令

Technically speaking, the kill command can send any signal to a process. You can use kill -KILL or kill -9 instead to kill a stubborn process.

从技术上讲,kill命令可以将任何信号发送到进程。 您可以使用kill -KILLkill -9来杀死一个顽固的进程。

pgrep (pgrep)

Given a search term, pgrep returns the process IDs that match it. For example, you could use the following command to find Firefox’s PID:

给定一个搜索词, pgrep返回与其匹配的进程ID。 例如,您可以使用以下命令来查找Firefox的PID:

pgrep firefox

pgrep Firefox

linux进程管理类命令_如何从Linux终端管理进程:您需要知道的10个命令

You can also combine this command with kill to kill a specific process. Using pkill or killall is simpler, though.

您也可以将此命令与kill结合使用以杀死特定进程。 不过,使用pkill或killall更简单。

杀死和杀死 (pkill & killall)

The pkill and killall commands can kill a process, given its name. Use either command to kill Firefox:

给定进程名称, pkillkillall命令可以杀死该进程。 使用以下任一命令杀死Firefox:

pkill firefox killall firefox

杀死火狐

linux进程管理类命令_如何从Linux终端管理进程:您需要知道的10个命令

We’ve covered pkill in more depth in the past.

过去我们更深入地介绍了pkill

伦尼斯 (renice)

The renice command changes the nice value of an already running process. The nice value determines what priority the process runs with. A value of -19 is very high priority, while a value of 19 is very low priority. A value of 0 is the default priority.

renice命令更改已经运行的进程的值。 nice值确定进程运行的优先级。 值-19是非常高的优先级,而值19是非常低的优先级。 值0是默认优先级。

The renice command requires a process’s PID. The following command makes a process run with very low priority:

renice命令需要进程的PID。 以下命令使进程以非常低的优先级运行:

renice 19 PID

renice 19 PID

linux进程管理类命令_如何从Linux终端管理进程:您需要知道的10个命令

You can use the pgrep trick above with renice, too.

您也可以将pgrep技巧与renice一起使用。

If you’re making a process run at a higher priority, you’ll require root permissions. On Ubuntu, use sudo for that:

如果要使进程以更高的优先级运行,则需要root权限。 在Ubuntu上,请使用sudo

sudo renice -19 #

须藤renice -19#

杀人 (xkill)

The xkill command is a way of easily killing graphical programs. Run it and your cursor will turn into an x sign. Click a program’s window to kill that program. If you don’t want to kill a program, you can back out of xkill by right-clicking instead.

xkill命令是一种轻松杀死图形程序的方法。 运行它,您的光标将变成一个x符号。 单击一个程序的窗口以杀死该程序。 如果您不想终止程序,则可以通过右键单击退出xkill。

linux进程管理类命令_如何从Linux终端管理进程:您需要知道的10个命令

You don’t have to run this command from a terminal — you can also press Alt-F2, type xkill and press Enter to use it from a graphical desktop.

您不必从终端运行此命令-您也可以按Alt-F2,键入xkill ,然后按Enter在图形桌面上使用它。

We’ve covered binding xkill to a hotkey to easily kill processes.

我们已经介绍了将xkill绑定到热键以轻松终止进程。



Do you have a favorite command we didn’t mention here, or another trick to share? Leave a comment and let us know.

您是否有此处未提及的收藏夹命令或其他分享技巧? 发表评论,让我们知道。

翻译自: https://www.howtogeek.com/107217/how-to-manage-processes-from-the-linux-terminal-10-commands-you-need-to-know/

linux进程管理类命令