ubuntu: control & view process

top

The top command is a commonly used command to view the usage of system resources and view the processes that occupy the most system resources.

top displays all processes in a column, and the process that takes up the most CPU resources will be displayed on the top.

The keyboard shortcut Ctrl-C will terminate the process currently running on the terminal.


htop

The htop command is an improved version of top.

By default, most Linux distributions do not have htop installed.

Installation instructions:

sudo apt-get install htop 

The htop command displays the same information as top, but its interface is more user-friendly.

You can use the keyboard arrow keys to select processes and take certain actions, such as killing processes or changing their priority.

The keyboard shortcut Ctrl-C will terminate the process currently running on the terminal.


ps

The ps command can list the running processes.

The following command lists all the commands running on your system:

ps -A 

The information listed by this command may be too much to read.

You can use the less command to pipe the output so you can scroll through it at your speed:

ps -A | less 

When you finish reading, you can press q to exit.

You can also use grep to pipe the output so that you can search for a process without using other commands.

The following command will search for the chrome process:

ps -A | grep chrome


pstree

The pstree command can also display process information.

pstree

It displays the progress in the form of a tree.

For example, your x system and graphics environment will appear under the display manager that generates the tree-like process.


kill

The kill command can kill a process based on the process ID.

You can use ps -A, top, or grep command to get the process ID.

kill [id]

Technically speaking, the kill command can send any signal to a process.

You can use kill -KILL [id] or kill -9 [id] to kill stubborn processes.


pgrep

Given a search keyword, the pgrep command will return all process IDs matching this keyword.

For example, you can use the following command to find the PID of chrome:

pgrep chrome

You can also combine this command with the kill command to kill a specific process.

However, it is easier to use pkill or killall.


pkill & killall

The pkill and killall commands can kill a process based on its name.

Use any of the following methods to kill the Firefox process:

pkill firefox 

killall firefox 

renice

The renice command is used to change the nice value of a process.

The nice value represents the priority of the process.

Conversely, 19 is a very low priority.

0 Is the default priority.

The process ID is required to run the renice command.

The following commands can make a process run at a very low priority:

renice 19 pid 

You can combine pregrep and renice.

If you want to increase the priority of the process, then you need to use root privileges.

On Ubuntu system, use sudo to obtain root privileges:

sudo renice -19 # 

xkill

The xkill command is a command that can easily kill graphics.

After running it, your cursor will become an x symbol.

Click the window of the corresponding graphics program to kill the program.

If you want to abandon the operation halfway, you can click the right mouse button to cancel.

You don't have to run this command in the terminal-you can press Alt-F2 on the graphical desktop, type xkill, and press Enter to run it.

We have bound xkill to hotkeys so that it is easier to kill the process.



Recommended Posts

ubuntu: control & view process
ubuntu view python installation path
VMware Ubuntu installation detailed process (pro-test)
Ubuntu19.10 open ssh service (detailed process)