The -9 (or KILL) argument to the kill command should only be used on POSIX-compliant systems when absolutely necessary. Why? The KILL signal cannot be processed by the process. This means that after killing a process with kill -9 , the child processes will remain in memory and become "orphaned" file system will be clogged with temporary files, shared memory segments will be active, sockets will be hung, and the atexit(3) function will not be executed at all. As a result, there is a risk of encountering unexpected and difficult-to-debug problems.

Instead, use the default TERM signal, and KILL only if less problematic signals prove ineffective:

$kill 6738
$ kill -INT 6738
$ kill -HUP 6738
$ kill -KILL 6738

If even the KILL signal fails to kill the process, the process is likely stuck on I/O or in some other unkillable state. You may need to reboot or forcefully unmount the glitched network drive.

Using the default kill -KILL is acceptable when dealing with a problematic application, for example, older versions of Netscape often terminated only with the KILL signal. However, this is a rare exception to the rule: use KILL for these known applications and only for them.

Problems encountered when terminating processes

Sending different signals sequentially can cause the following problems: First, the process may take seconds, or even tens of seconds, to terminate gracefully. One product I used took over 30 seconds to terminate correctly after receiving the TERM signal. Fortunately, this feature was discovered during testing, so a suitable script was written for this case. Secondly, sometimes there are situations where an old process has terminated while a new process has taken over its ID in the interval between the TERM and KILL signals. Systems with high process turnover and systems where the kernel assigns PIDs randomly, such as OpenBSD, are especially at risk of this. Checking the process name or its PPID doesn't always help, since the new process could be a fork of the same parent and have the same name, so particularly paranoid scripts might also check the process's creation time or other metadata before sending the signal. These situations may occur rarely, but they are worth taking into account if you have to deal with a critical process.

Process termination signals

Process termination signals can be identified by name or sequence number: kill -1 and kill -HUP are equivalent. However, using the signal name is safer because specifying a -1 argument can easily mistype it, sending the signal to another process or even a group of processes. Also, always try to use a name in your scripts, as this will help you better understand what type of signal is being sent to whoever will be reading your code.

The HUP signal freezes the shell, so it good way clear the shell hanging waiting for input, or close the SSH session.

For more information about process termination signals, see

Be that as it may, sooner or later we are faced with the need to kill a buggy or hung process in Linux. Yes, yes, some applications in Linux sometimes freeze, despite their stability. It is in these cases that a wonderful utility will come in handy Kill. Let's figure out how to use this utility.

Each process in Linux has its own identifier called PID. Before stopping a process, you need to define it PID. The bottom line is that we need to find this identifier, let's open, for example, any program and try to find its identifier.

Hung process ID

To search we need commands ps and grep. Team ps- will display for us a list of active processes in the system and information about them, and the command grep- will search the results of the command ps. So let's open a terminal ( ctrl+alt+t) and look at the active processes

p.s. axu

As you have already noticed, the list is very large and scrolling through it to find the process we need is a waste of time, for this we will use a wonderful program grep. To find the process we need, after entering grep, specify the application we are looking for. Using Viber as an example, it looks like this:

p.s. | grep viber pol 22685 0.0 1.9 647748 76620 ? Sl 13:01 0:04 /usr/bin/python /usr/bin/viberwrapper-indicator pol 22697 3.0 5.4 5402084 216120 ? Sl 13:01 4:52 /opt/viber/Viber pol 24068 0.0 0.0 17192 2216 pts/0 S+ 15:41 0:00 grep --color=auto viber

The first line contains the running viberwrapper-indicator application; you can read about this application. The second line is Viber itself, which we will “extinguish” today, but what is the third line? The third process is the process itself grep, since we specified the word viber as a search parameter, and grep found itself in the command output ps.

There is another easier way to find out PID process is a command pidof, which takes the process name as a parameter and outputs its PID. Be careful about case if the process name starts with capital letter, and you write it with a small letter (or vice versa), then pidof will not be there

pidof Viber

As you already noticed, I was given 3 lines with the active Viber application

Completion of the process or, more simply put, “Murder”

Now we know the Viber process ID and we have the opportunity to “Kill” it:

kill 22697

In general, the kill command is intended to send a signal to a process. By default, if we do not specify any attributes, the SIGTERM signal (from the word termination) is sent. SIGTERM tells the process to terminate. Each signal has its own number. SIGTERM is numbered 15. A list of all signals (and their numbers) that the command can send kill, can be derived by running kill -l. To send the SIGKILL signal (numbered 9) to process 22697, run on the command line:

kill -9 22697

The SIGTERM signal may not stop the process (for example, if the signal is intercepted or blocked), but SIGKILL always kills the process, since it cannot be intercepted or ignored.
Look full list attributes can be done by running the command

kill -l

Today we will talk about how to Ubuntu Linux deal with processes that are stuck and you cannot terminate them. They devour system resources by loading the system, eating off a decent portion random access memory, which creates problems such as slowdown of the computer or partial freezing of the system for short periods of time. There are different situations, sometimes the desktop freezes, sometimes the application freezes, sometimes the desktop environment freezes, it is with these situations that we will look for a way out of how to do without rebooting the system and not turning off the computer with the button on system unit computer since this is not a good solution.

Sometimes there is a need to kill a process in Ubuntu Linux, how to do it correctly and not cause harm, we will discuss both console solutions and through the graphical interface.

Today we will talk about how to deal with processes in Ubuntu Linux that are frozen and you cannot terminate them. They devour system resources by loading the system, eating up a decent part of the RAM, which creates problems such as slowdown in the computer or partial freezing of the system for short periods of time. There are different situations, sometimes the desktop freezes, sometimes the application freezes, sometimes the desktop environment freezes, it is with these situations that we will look for a way out, how to do without rebooting the system and not turning off the computer with a button on the system unit of the computer as this is not a good solution .

When working with Ubuntu Linux, you probably already have questions:

How to determine the PID in order to subsequently kill the process / application

If you don't want to run the command top or another more powerful analogue htop, then bother yourself with searching for the ID of this or that process ID, there is an easier way out / solution to find PID process, you can use the command " pidof" or " PS".

Let's say we need to find out the application process ID Google Chrome What we do in this situation is open the terminal Ctrl + Alt + T and execute the command in the terminal:

Pidof chrome

we get the output:

9497 9183 9123 8815 8788 6042 6033 5938 5916 5911 5908 5900 5892 5836 5831 5819

almost ready, we have determined the PID, read below on how to kill the process.

How to kill a process in Linux by PID

We have determined which PID is in the application that we want to kill, from the one described above, you see that I now have many tabs running in my browser, plus individual browser processes, in total there are 16 IDs, to kill them all, we run the command:

Sudo kill 9497 9183 9123 8815 8788 6042 6033 5938 5916 5911 5908 5900 5892 5836 5831 5819

You can also view all active processes in the system by running the command:

Sudo ps axu

yes, it's that simple. Instead of Chrome there can be any other application, skype or some other.

You can also use additional command to detect the process ID of the application you want to kill:

Ps-A | grep -i name-app

Instead of name-app we write the name of the application, do not enter the full name manually, use auto-detection using the " keys" TAB". As a result, this command will display the operating time of the required process and, accordingly, its PID, which you can use to kill, let's check the operation of the command, run in the terminal:

Ps-A | grep -i skype

we get the following result:

9257? 00:00:57 skype

everything we need is at a glance, there is an ID and we also see what time it is this process Already working.

How to Use the Kill Command in Linux

I have already described how to get the PID identifier above, then all we have to do is use this PID together with kill, which will kill the process we don’t like, see the details a little lower.

We received the ID and can now kill the application:

Sudo kill 9257

That's all, the application is killed.

How to kill a process in Linux by name

To kill a process by name you can use the killall command, you must first understand that this command kills all processes that have the same name. This is very convenient, since in this situation we do not need to look for the PID of the process we need, for example, we want to close the Skype application, we will execute the command in the terminal:

Sudo killall skype

also an option:

Sudo killall -s 9 skype

at the same moment the application stops working, this is how you can easily kill processes you don’t like.

The death command, what you should not do in the terminal

I previously wrote material about bad advice, which commands should not be executed in the terminal so as not to kill the system, but the list is not perfect and it can be supplemented with many more commands, one of which you will find below.

Here's an example of a death command:

Sudo kill -9 -1

this command will kill all running on this moment processes. I would not recommend doing this because the consequences can be unpredictable and you will most likely have to restart the system without a graphical interface. In case it suddenly refuses GUI, then open the terminal using the commands CTRL+ALT+F1, each new window opens by the same analogy, simply changing F1 to F2 and so on.

You can also get help on the commands used above through the terminal by running the commands:

Man ps man grep man pidof man kill man killall

This concludes our short material, if you don’t understand something, ask in the comments to the material below.

We will show you how to kill a process in Linux. One of the main advantages of Linux is the ability to terminate a process without having to reboot the server. In this article, we will show you how to kill a process in Linux using the kill, pkill and killall command.

1. What is PID

Before we begin, we need to know what a Process ID (PID) is.

PID represents the digital identification of a process in . Each process has a unique PID. In fact, for example, the first process that starts in the system at Linux based, this is a process, and its PID is set to 1. This process is the parent of all other processes. The init process cannot be killed using kill commands, and this ensures that it will not be killed accidentally.

Now, in order to find the PID of each running process on the server, we can run the following command:

This gives us a list of all running processes and their corresponding PIDs.

If we want to find the PID of a specific process, we can use the pidof command followed by the process name. For example, to find out the PID of our MySQL process, you can run the following command:

Pidof mysql

For even more detailed information, we can use the command ps aux together with grep:

PS aux | grep mysql

Now that we know what a PID is and how to find the PID of a specific process, we can move on to the next section and learn how to kill it.

2. Kill a process using the kill command in Linux

There are a few important rules that we need to know before we start using the kill command.

  • You can only kill native processes that belong to your user ID
  • You cannot kill other users' processes
  • You can't kill system processes(unless you are a superuser)
  • The root user can kill any other user's process and any system process

When we kill a process with the kill command, we are actually sending the specific PID signal we want to kill. The following signals are used by the kill command:

1 = Hung up 9 = Kill 15 = Terminate

The hung up signal is rarely used. Most often we use the kill signal, and if it doesn't work, then we can use the Terminate signal.

So once we find the PID of the process we want to kill, use one of the methods we described earlier, we can use the command kill -9 PID to kill the process from that specific PID.

For example, if the PID is 6738, then we can use the following command:

Kill -9 6738

3. Kill a process using pkill command in Linux

If you want to use the process name instead of its PID to kill it, then you can use the pkill command. For example, if the process we want to kill is called , then we can use the following command to kill it:

Pkill mysql

4. Kill a process using the killall command in Linux

The two previous commands are used to kill only one specific process. But, if we want to kill a process along with all its child processes we can use the command killall:

Killall mysql

In this example, we will kill the MySQL process and all its child processes.

They are the most common examples of process killing in Linux.

Despite the fact that Linux is more stable than Windows in terms of the operation of programs and various services, anything can happen and sometimes it becomes necessary to terminate the Linux process. This may be necessary if the program crashed when you launched a system service in the background through the terminal rather than the initialization system, as well as in many other cases when it is easier to kill the Linux process by rebooting the entire system.

In this article, we will look at some of the most common ways to terminate a Linux process. We will describe in detail how the process is stopped and how to do everything correctly.

Operating room process management Linux system carried out using signals. Including the completion of any process. Signals are transmitted by the system, but they can also be transmitted by the user using special teams or even keyboard shortcuts in the terminal. When a process receives a signal to terminate, it must perform some preparatory steps.

It is necessary to terminate child processes, delete temporary files, sockets, and so on. But depending on the complexity of the situation, the process may not respond to all signals. Let's look at the main signals that are used to complete the process:

  • SIGINT- the most harmless termination signal, means Interrupt. It is sent to the process launched from the terminal using the Ctrl+C keyboard shortcut. The process correctly completes all its actions and returns control;
  • SIGQUIT - this is another signal that is sent, using a keyboard shortcut, to a program running in the terminal. It tells it to exit, and the program can terminate gracefully or ignore the signal. Unlike the previous one, it generates a memory dump. Keyboard shortcut Ctrl+/;
  • SIGHUP- informs the process that the connection with the control terminal is broken, sent mainly by the system when the connection to the Internet is broken;
  • SIGTERM- immediately terminates the process, but is processed by the program, so it allows it to terminate child processes and free all resources;
  • SIGKILL- also immediately terminates the process, but, unlike the previous option, it is not transferred to the process itself, but is processed by the kernel. Therefore, resources and child processes remain running.

It is important to understand that you need to give the process the opportunity to complete correctly. It is advisable that ports and sockets are freed, temporary files are closed and temporary files are deleted. Therefore, never send SIGKILL straight away. Send termination signals in the sequence as listed above.

At first Ctrl+C, if possible, then SIGTERM - although it terminates the process, it does this culturally, and only as a last resort SIGKILL. Now let’s look at how to kill a process using pid Linux in practice. If you always use SIGKILL, then this picture comes to mind:

How to kill a Linux process?

The kill utility is used to signal processes in Linux. Its syntax is very simple:

$ kill - process pid signal

The signal is one of the above signals to complete the process. By default, if this parameter is not specified, the SIGTERM signal is used, which is very correct. We also need to indicate which process needs to be terminated. To do this, a unique process identifier - PID - is used.

Let's say we are running the ping utility. We want to terminate it using kill. Then, first we find out its identifier using the ps command:

ps aux | grep ping

The first line will display the ping utility itself, and the second line will display the ps program itself. We take the desired PID and terminate the process using SIGTERM:

kill -TERM 20446

And only if after this command the process continues to hang, and you can check this by running ps. Only now you can perform SIGKILL:

kill -KILL 20446

Now let's check again:

If the process is running as superuser, then naturally you need to use sudo. It is not always convenient to kill a process by its PID, at least because you still need to find out this PID. We could make complex constructs using xargs to automatically calculate the pid from the process name and terminate it immediately, but this is not necessary. Special utilities already exist.

How to kill a process using pkill

The pkill utility is a wrapper around kill, it behaves exactly the same and has the same syntax, only it needs to pass the process name as the process identifier. The utility scans the proc directory and finds the PID of the first process with that name, then sends a SIGTERM to it. This way you can kill the process called Linux. For example, if we want to complete the same ping:

You can also manually set the signal type:

pkill -TERM ping

Instead of ps, you can use the pgrep utility to find the pid of the process, making sure our program is completed:

But if the program has created several processes for you, for example, the chromium or firefox browser creates a separate process for each of the tabs, then this utility will be of little help. Here we need the next option.

How to stop a process using killall

killall works similarly to the two previous utilities. It also takes the process name as a parameter and looks for its PID in the /proc directory. But this utility will detect all processes with that name and terminate them. For example:

As you can see, several processes are running, all that remains is to stop the Linux process using killall:

The command will terminate all running ping utilities, you can verify this by running pgrep again:

conclusions

In this article, we looked at how to kill a Linux process. This task can be very rewarding at times, but it is important to understand that it needs to be done correctly. This is not to say that passing SIGKILL instead of SIGTERM is very dangerous, but it is not worth doing. I hope this information was useful to you.