Hardware

How to handle and kill processes from the console in linux: kill, killall, pkill ...

Table of contents:

Anonim

We know that in Linux, the console provides us with tools that are extremely powerful for system administration. That is why, today we will talk about commands for Process Management from the console in Linux. It is probable that several of them already know them, but it never hurts to do a review; since these allow us from viewing, setting their priority, to killing processes.

Index of contents

Process management from the console in Linux

top

This is one of the classic Linux commands for process handling. It allows you to view the resources used by the system and thus identify which of them is consuming the most.

Syntax:

top

htop

Let's say it is an improved version of top. Usually Linux distributions do not have it installed by default.

If they don't have it on their system, they run the following to install it:

sudo apt-get install htop

Its main improvement is that the output is much easier to interpret compared to top. Additionally, it allows other types of operations to be carried out on processes, such as killing a process, in a very easy way using the keys shown in the following image:

pgrep

This command allows us to determine the PID of the process that matches the search for the supplied keyword. PID stands for "Process Identifier". Let's see an example:

pgrep firefox

It will return the PID of the "firefox" process.

renice

This command helps us in modifying the "nice" value of a process that is running.

The "nice" value is what determines the priority of a specified process. Its scale is as follows:

  • The value of -19 represents a very high priority. Conversely, the value 19 determines a low priority. The default value is 0.

The renice command needs the PID of a process as a parameter.

Syntax:

renice 19 "PID"

ps

It is the universal default Linux command for process management. You can view the processes and perform operations on them. It is quite practical because it allows you to link it with other commands. An example of them is using "grep" to search for a specific process, making use of the famous Pipes.

Example:

ps -A | grep firefox

Where "grep firefox" searches for Firefox processes.

pstree

This command allows us to visualize all the processes with their respective dependencies, in the form of a tree.

Terminate processes in Linux

Linux-based operating systems incorporate a set of useful tools to end processes that have become stuck or that we no longer require to continue running. At this point we will expand a bit since there are 4 ways to end a process and it is a fundamental part of managing processes in Linux. It can be through its name, also specifying a part of its name, directly by the PID or even pointing with the cursor at the window of said process. Next we will see one by one.

Kill: using the PID to kill the process

It is the most complicated but at the same time the most accurate way, since the PID is a unique identifier for each process running at a given moment.

Kill allows us to send different types of signals, which can close a process or a group of them. The default signal is TERM if no type is specified.

WE RECOMMEND YOU Want Ubuntu 17.04 to look like Windows?

The following types of signal are the most common:

  • SIGHUP: It is used when the console does not respond or if control over the process is lost. It is responsible for reloading its configuration files as well as its possible log files. SIGKILL: This mode is the most radical to end a process, it is used when it no longer responds. No data will be saved as it is not a clean way to close the process. SIGTERM: It is the default mechanism to kill the process.

Example:

kill 22298

Where, 22298 represents the PID of the process.

killall: kill a process using its name

It is a very simple command. One thing to keep in mind is that, in case there are several instances of the program running, the command will take care of closing all of them.

Syntax:

killall process_name

pkill: kill a process using part of its name

pkill gives us the option to annihilate the process through your name or even a part of it. This frees us from the need to remember the PID to specify the signal. However, all processes whose names contain the specified word will be closed.

Its execution would be:

pkill process_name part

We recommend reading the redirects and pipes in Linux.

xkill: kill a process by selecting the window with the mouse

Of the entire group, this is the most practical and simple. Just press the Alt + F2 keys, followed by this a dialog box will be displayed. This box will allow you to perform command execution. We write xkill. Then the courses will become a skull and by clicking on one of the windows, goodbye process!

Leave your experience in the comments, share with us which of this group of commands is useful for you and why?

Hardware

Editor's choice

Back to top button