We kill processes in Linux - the ps, kill and killall commands. Process ID Process ID (PID) How to find a process in Linux


Do you think the Linux operating system can take care of itself automatically? When everything works fine or you don't need any non-standard features, yes. But sometimes your intervention in her work may be needed.

In Linux, for each individual program, a process is created when it starts. It doesn't matter whether you run the program manually yourself or the system or the kernel does it. For example, the initialization program, which is launched immediately after the kernel has finished loading, also has its own process with the identifier 0. Processes in linux can be described as containers in which all information about the state and execution of the program is stored. If the program works well, then everything is fine, but if it hangs or you need to configure it to work, you may need to manage processes in Linux.

This article will cover an extensive topic, we will consider such possibilities:

  • View running processes
  • Viewing information about processes
  • Finding processes in Linux
  • Terminating processes
  • Limiting the memory available to a process

I could not help but include the first points in the article, but they are very simple and we will not analyze them in great detail. But everything else may seem complicated and insufficiently described.

Let's start by understanding the terms. Basically, a process is every program. As I said, a separate process is created for each program that is launched. As part of the process, the program is allocated processor time, RAM and other system resources. Each process has its own identifier, Proccess ID or simply PID, and most often Linux processes are determined by them. The PID is not determined by chance, as I already said, the initialization program receives PID 1, and each next program that is launched gets one more. Thus, the PID of user programs already reaches several thousand.

In fact, Linux processes are not as abstract as they seem to you now. It is quite possible to try to touch them. Open your file manager, go to the root directory, then open the / proc folder. See a bunch of numbers here? So that's all - the PID of all running processes. Each of these folders contains all the information about the process.

For example, let's look at the folder of process 1. There are others under directories and a lot of files in the folder. The cmdline file contains information about the command to start the process:

cat / proc / 1 / cmdline

/ usr / lib / systemd / systemd

Since I use the Systemd init system, the first process is launched for it. Anything can be done with the / proc directory. But this is very inconvenient, especially considering the number of running processes on the system. Therefore, there are special utilities for the implementation of the necessary tasks. Let's move on to reviewing utilities that allow you to implement process control in Linux.

Linux process control

Linux has a very large number of utilities for solving various tasks of managing processes. These are such multifunctional solutions as htop, top, as well as simple utilities, for example, ps, kill, killall, who, etc. I will not consider graphical utilities in this article, and I will not consider top either. The first is because it is too simple, the second is because htop is better. We will focus on working with htop and its GNU-style utility counterparts, one utility one function.

Let's install htop if you don't already have it. Ubuntu does it like this:

sudo apt install htop

On other distributions, you just need to use your package manager. The package name is the same.

View running processes

This is a very simple task, and it is also easy to solve. There are many utilities for this, ranging from regular ps to more advanced interactive top, htop and so on.

Opening htop, we immediately see a list of running processes. Of course, not all linux processes are displayed here, there are a lot of them in the system, you already know, they all will not fit on one screen. By default, processes launched as your user are listed:

You can see the following information about the process:

  • PID- process id
  • USER- the user from whom the process was started
  • PRI- priority of the linux process at the kernel level (usually NI + 20)
  • NI- priority of the process execution from -20 to 19
  • S- process state
  • Cpu- used processor resources
  • MEM- used memory
  • TIME- process time

You can add additional parameters to the display, but these are the main ones. You can add parameters using the Setup menu. Everything is very simple there, read the tips and follow the directions. For example, added PPID parameter:

A very important feature of the program is that you can sort processes in Linux by the desired parameter. Just click on the parameter name, it will be highlighted in green and the sort will be performed. For example, if you want to see in what order the processes were started, sort by PID:

There is also an interesting opportunity to arrange processes in the form of a tree. You will be able to see which process started this or that process. Press F5 to display the tree:

You can do much the same thing with ps. Only here there is no such convenient interactive mode. Everything is done with options.

Let's consider the main options that we will use:

  • -e- display information about all processes
  • -a- display information about all the most frequently requested processes
  • -t- show only processes from this terminal
  • -p- show information only about the specified process
  • -u- show processes of only a certain user

In short, to view all currently active processes in linux, a combination of aux options is used:

The program shows all the same parameters, only there is no interactive interface. You think it is impossible to sort the processes here, but you are mistaken, you can. There is a sort option for this. You can sort them by any field, for example:

ps aux --sort =% mem

The list will be sorted in reverse order, with more values ​​at the bottom and less at the top. If needed in reverse order, add a minus:

ps aux --sort = -% cpu

Linux process priorities or any other parameters can be used as a sorting field. You can also truncate the output if you do not need to display all the information:

It would seem that ps has no way of costing process trees. But not really, there is a separate command for this:

Finding processes in Linux

The list of processes is good. But sometimes, when a process hangs and we need to kill the Linux process or we need to carry out some action with it, we need to select this process from the list, find out its PID and information about it.

You can use the F3 key to find the linux process in htop. Press F3 and type the word you want. Next, to go to the next occurrence, press F2 or Esc to complete the search:

You can also use the htop filter to find processes in htop. Press F4, enter a word and only linux processes whose name includes this word will be displayed.

There is no filtering in ps, but we can use grep by redirecting ps output to it to find the linux process:

ps aux | grep chromium

This is a very commonly used command.

Changing the priority of processes

The linux process priority means how much more CPU time will be devoted to this process compared to others. So we can very finely tune which program will run faster and which will be slower. The priority value can range from 19 (minimum priority) to -20 - the maximum priority of the linux process. Moreover, you can reduce the priority with the rights of a regular user, but to increase it, you need superuser rights.

Htop uses the Nice parameter to control the priority. Let me remind you that Priv is just an amendment, in most cases it is more than Nice by 20. To change the priority of a process, simply place the cursor on it and press F7 to decrease the number (increase the priority) or F8 to increase the number.

But you don't need to use htop for this Linux process control task either. You can do everything with other commands. For example, the nice command. Using it, you can specify the priority for the started process:

nice -n 10 apt-get upgrade

Or change the priority for an existing one by its pid:

renice -n 10 -p 1343

Terminating processes in Linux

If the process is frozen and unresponsive, it must be terminated. In htop, to kill a Linux process, simply position the cursor over the process and press F9:

The system uses certain signals to control the processes, there are signals that indicate the process to end. Here are some basic signals:

  • SIGKILL- ask the process to save the data and end
  • SIGTERM- end the process immediately, without saving

In general, there are several dozen signals, but we will not consider them. Let's send the SIGKILL signal:

You can also use the kill utility:

You can also kill the process by name:

killall chromium

Limiting processes

Linux process control allows you to control almost everything. You've already seen what can be done, but more can be done. With the ulimit command and the /etc/security/limits.conf configuration file, you can restrict processes from accessing system resources such as memory, files, and processor. For example, you can limit the memory of a Linux process, the number of files, etc.

The file entry looks like this:

<домен> <тип> <элемент> <значение>

  • domain- username, group name or UID
  • a type- type of restrictions - soft or hard
  • element- a resource that will be limited
  • meaning- the required limit

Hard limits are set by the superuser and cannot be changed by regular users. Soft, soft limits can be changed by users using the ulimit command.

Let's consider the main restrictions that can be applied to processes:

  • nofile
  • as- the maximum amount of RAM
  • stack- maximum stack size
  • cpu- maximum processor time
  • nproc- maximum number of processor cores
  • locks- number of locked files
  • nice- the maximum priority of the process

For example, let's limit the processor time for the processes of the user sergiy:

sergiy hard nproc 20

You can view the restrictions for a specific process in the proc folder:

cat / proc / PID / limits

Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 204800 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 23562 23562 processes
Max open files 1024 4096 files
Max locked memory 18446744073708503040 18446744073708503040 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 23562 23562 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us

Restrictions changed in this way will take effect after a reboot. But we can also set limits for the current shell and the processes it creates using the ulimit command.

Here are the command options:

  • -S- soft limitation
  • -H- hard limit
  • -a- display all information
  • -f- maximum size of created files
  • -n- maximum number of open files
  • -s- maximum stack size
  • -t- maximum amount of processor time
  • -u- the maximum number of running processes
  • -v- maximum amount of virtual memory

For example, we can set a new limit on the number of files that can be opened:

Now we look:

Let's set the RAM limit:

ulimit -Sv 500000

Let me remind you that this limitation will be relevant for all programs running in this terminal.

conclusions

That's all. Now, managing processes in Linux won't give you any problems. We have considered this topic in great detail. If you have any questions or suggestions for supplementing the article, write in the comments!

Despite the fact that Linux is more stable than Windows in terms of the operation of programs and various services, anything happens and sometimes it becomes necessary to terminate the Linux process. This may be needed if the program crashed when you started the system service in the background through the terminal, and not the init system, and in many other cases, when it is easier to kill the Linux process, reboot the entire system.

In this article, we'll go over a few of the most common ways to end a Linux process. Let's describe in detail how the process stops and how to do everything right.

Process control in the Linux operating system is 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 commands or even keyboard shortcuts in the terminal. When a process receives a signal to terminate, it must perform some preparatory steps.

You need to terminate child processes, delete temporary files, sockets, and so on. However, depending on the complexity of the situation, the process may not respond to all signals. Consider the main signals that are used to complete the process:

  • SIGINT- the most harmless completion signal, means Interrupt. It is sent to a 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 with a keyboard shortcut to a program running in a terminal. It tells her to exit and the program can complete gracefully or ignore the signal. Unlike the previous one, it generates a memory dump. The shortcut keys Ctrl + /;
  • SIGHUP- informs the process that the connection with the control terminal is broken, it is sent mainly by the system when the connection to the Internet is broken;
  • SIGTERM- immediately terminates the process, but is processed by the program, therefore, allows it to terminate child processes and free all resources;
  • SIGKILL- also terminates the process immediately, but, unlike the previous version, 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 allow the process to complete correctly. It is desirable that ports and sockets be freed, closed and temporary files deleted. Therefore, never send SIGKILL right away. Send completion signals in sequence as listed above.

First Ctrl + C, if possible, then SIGTERM - although it ends 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 do I kill a Linux process?

Linux uses the kill utility to send signals to processes. Its syntax is very simple:

$ kill -signal of process_pid

A 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 completed. For this, a unique process identifier is used - PID.

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

ps aux | grep ping

The first line displays the ping utility itself, and the second displays the ps program itself. We take the desired PID and terminate the process with 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 execute SIGKILL:

kill -KILL 20446

Now we check again:

If the process is running as superuser, then of course 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 pile up 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 end a process with pkill

The pkill utility is a wrapper for kill, it behaves exactly the same, and has the same syntax, except that it needs to be passed the name of the process as a process ID. 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 terminate 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 finished:

But if the program has created several processes for you, for example, the chromium browser or firefox create a separate process for each of the tabs, then this utility will not help much. The next option is needed here.

How to stop a process with killall

killall works in a similar way to the previous two 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 instance:

As you can see, several processes are running, it remains to stop the Linux process with killall:

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

conclusions

In this article, we have covered how to kill a Linux process. This task can be very useful 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 you shouldn't. Hope this information was helpful to you.

We will show you how to kill a process in Linux. One of the main advantages of Linux is the ability to complete the 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 commands.

1. What is PID

Before we start, we need to know what a process ID (PID) is.

The PID is the digital identification of the process in the. Each process has a unique PID. Indeed, for example, the first process that starts on a Linux-based system 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 with kill commands, and this ensures that it is not accidentally killed.

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 details, 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 find out 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 using the kill command.

  • You can only kill your own processes that are owned by your user id
  • You cannot kill the processes of other users
  • You cannot kill system processes (unless you are superuser)
  • The root user can kill the process of any other user and any system process

When we kill a process with the kill command, we are actually sending the specific signal to the PID controller that 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.

Therefore, 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 particular PID.

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

Kill -9 6738

3. Kill the process with the 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 the process using the killall command in Linux

The previous two 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 of its child processes.

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

Basically, we look at the PID to kill the unresponsive program and it is similar to the Windows Task Manager.

The Linux GUI also offers the same functionality, but the CLI is an efficient way to perform a kill operation.

What is Process PID?

PID stands for Process Identification Number, which is commonly used by most operating system kernels such as Linux, Unix, macOS, and Windows.

This is a unique identification number that is automatically assigned to each process when it is created in the operating system.

A process is an executable instance of a program.

Each time, the process ID will receive changes to all processes except init, since init is always the first process on the system and is the ancestor of all other processes. This is PID - 1.

The default maximum PID value is 32,768.

# cat / proc / sys / kernel / pid_max

On 32-bit systems, 32768 is the maximum, but we can set any value up to 2 ^ 22 (approximately 4 million) on 64-bit systems.

Why do we need so many PIDs, you may ask? because we cannot reuse the PID right away. Also to avoid possible mistakes.

The PIDs for running processes on the system can be found using the following nine methods, such as pidof command, pgrep command, ps command, pstree command, ss command, netstat command, lsof command, fuser command, and systemctl command.

  • pidof: pidof - find the process id of the running program.
  • pgrep: pgre - Search or signal processing based on name and other attributes.
  • ps: ps - Reports a snapshot of the current processes.
  • pstree: pstree - displays a tree of processes.
  • ss: ss is used to display socket statistics.
  • netstat: netstat displays a list of open sockets.
  • lsof: lsof - list of open files.
  • fuser: process identifiers in the term list of all processes that open one or more files
  • systemctl: systemctl - Manage systemd system and service manager

In this tutorial, we'll take a look at the Apache process ID for validation.

Method-1: Using the pidof command

pidof is used to find the process id of a running program.

It prints these identifiers to standard output.

To demonstrate this, we will get the Apache2 process ID from the Debian 9 system.

# pidof apache2 3754 2594 2365 2364 2363 2362 2361

From the above, you may have difficulty identifying the process ID as it shows all PIDs (including parent and child) with the process name.

Hence, we need to figure out the parent PID (PPID) that we are looking for.

This may be the first number. In my case it is 3754 and it is shown in descending order.

Method-2: Using the pgrep command

pgrep looks at the current processes and lists the process IDs that match the selection criteria for stdout.

# pgrep apache2 2361 2362 2363 2364 2365 2594 3754

This is also similar to the above output, but this one tends to truncate the results in ascending order, which clearly indicates that the parent PID is the last one.

In my case, it is 3754.

Note. If you have multiple process ids, you may run into the problem of identifying the parent process ids when using the pidof & pgrep command.

Method-3: Using the pstree command

pstree shows running processes as a tree.

The tree is rooted in either pid or init if pid is omitted.

If a username is specified in the pstree command, then the entire process owned by the corresponding user is displayed.

pstree visually concatenates identical branches by enclosing them in square brackets and prefixing them with the number of repetitions.

# pstree -p | grep "apache2" | - apache2 (3754)- + - apache2 (2361) | | -apache2 (2362) | | -apache2 (2363) | | -apache2 (2364) | | -apache2 (2365) | `-apache2 (2594)

To get only one parent process, use the following format.

# pstree -p | grep "apache2" | head -1 | - apache2 (3754)- + - apache2 (2361)

The pstree command is very simple because it separates the parent and child processes separately.

Method-4: Using the ps command

ps displays information about the selection of active processes.

It displays the process id (pid = PID), the terminal associated with the process (tname = TTY), the cumulative processor time in hh: mm: ss format (time = TIME), and the executable name (ucmd = CMD).

By default, the output file is not sorted.

# ps aux | grep "apache2" www-data 2361 0.0 0.4 302652 9732? S 06:25 0:00 / usr / sbin / apache2 -k start www-data 2362 0.0 0.4 302652 9732? S 06:25 0:00 / usr / sbin / apache2 -k start www-data 2363 0.0 0.4 302652 9732? S 06:25 0:00 / usr / sbin / apache2 -k start www-data 2364 0.0 0.4 302652 9732? S 06:25 0:00 / usr / sbin / apache2 -k start www-data 2365 0.0 0.4 302652 8400? S 06:25 0:00 / usr / sbin / apache2 -k start www-data 2594 0.0 0.4 302652 8400? S 06:55 0:00 / usr / sbin / apache2 -k start root 3754 0.0 1.4 302580 29324? Ss Dec11 0:23 / usr / sbin / apache2 -k start root 5648 0.0 0.0 12784 940 pts / 0 S + 21:32 0:00 grep apache2

From the above output, we can easily identify the parent process id (PPID) based on the process start date.

In my case the apache2 process was started by @ Dec11 which is the parent and the others are children. Apache2 PID is 3754.

Method-5: Using the ss command

ss is used to display socket statistics.

It allows you to display information similar to netstat.

It can display more TCP and state information than other tools.

It can display statistics for all socket types like PACKET, TCP, UDP, DCCP, RAW, Unix domain, etc.

# ss -tnlp | grep apache2 LISTEN 0 128 ::: 80 ::: * users: (("apache2", pid = 3319, fd = 4), ("apache2", pid = 3318, fd = 4), ("apache2", pid = 3317, fd = 4))

Method-6: Using the netstat command

netstat - Displays network connections, routing tables, interface statistics, masquerading and multicast connections.

By default, netstat displays a list of open sockets.

If you do not specify any address families, the active sockets of all configured address families are listed.

This program is outdated. The replacement for netstat is ss.

# netstat -tnlp | grep apache2 tcp6 0 0 ::: 80 ::: * LISTEN 3317 / apache2

Method-7: using the lsof command

lsof - list of open files.

The lsof Linux command displays information about the files open for processes running on the system.

# lsof -i -P | grep apache2 apache2 3317 root 4u IPv6 40518 0t0 TCP *: 80 (LISTEN) apache2 3318 www-data 4u IPv6 40518 0t0 TCP *: 80 (LISTEN) apache2 3319 www-data 4u IPv6 40518 0t0 TCP *: 80 (LISTEN)

Method-8: Using the fuser command

The fuser utility should write to standard output the process IDs of processes running on the local system that open one or more named files.

# fuser -v 80 / tcp USER PID ACCESS COMMAND 80 / tcp: root 3317 F .... apache2 www-data 3318 F .... apache2 www-data 3319 F .... apache2

Method-9: Using the systemctl command

systemctl - Manage systemd system and service manager.

It is a replacement for the old SysV system control and most modern Linux operating systems have been adapted by systemd.

# systemctl status apache2 ● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; disabled; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service. d └─apache2-systemd.conf Active: active (running) since Tue 2018-09-25 10:03:28 IST; 3s ago Process: 3294 ExecStart = / usr / sbin / apachectl start (code = exited, status = 0 / SUCCESS) Main PID: 3317 (apache2) Tasks: 55 (limit: 4915) Memory: 7.9M CPU: 71ms CGroup: /system.slice/apache2.service ├─3317 / usr / sbin / apache2 -k start ├─3318 / usr / sbin / apache2 -k start └ ─3319 / usr / sbin / apache2 -k start Sep 25 10:03:28 ubuntu systemd: Starting The Apache HTTP Server ... Sep 25 10:03:28 ubuntu systemd: Started The Apache HTTP Server.


Despite its stability, some applications on Linux sometimes freeze. Sometimes apps stop responding or just run so slowly that they can't be closed correctly. One way to "kill" a running application in Linux is by using commands such as kill or killall. Let's look at how to use these commands, find the PID of a process, and send the SIGKILL signal.

By a process we mean a copy of the program running on the system. For example, if you have three calculator windows open (eg gcalctool), you have started three processes.

Finding the PID of a hung process

Every process in Linux has its own identifier called a PID. Before you can stop the process, you need to determine its PID. To do this, we will use the ps and grep commands. Ps command is intended for displaying a list of active processes in the system and information about them. Grep command runs at the same time as ps (in a pipe) and will search the results of the ps command. You can display a list of all processes by executing in the command line:

But, as a rule, the list is very long and it is not so easy to find the process that we want to "kill". This is where grep comes in. For example, to find information about a process named gcalctool, run the command:

Ps axu | grep gcalctool

The grep command will search the results of the ps command and display only those lines that contain the string (word) gcalctool. There is one interesting detail here, for example, if you do not have the gcalctool application running, then after executing ps axu | grep gcalctool You'll get:

$ ps axu | grep gcalctool yuriy 25587 0.0 0.0 10636 884 pts / 2 S + 10:20 0:00 grep --color = auto gcalctool

That is, we got the grep process itself, since we specified the word gcalctool as a parameter to the command, and grep found itself in the output of the command ps.

If the gcalctool process is running, then we get:

[email protected]: ~ $ ps axu | grep gcalctool yuriy 25609 7.6 0.4 500840 17964? Sl 10:20 0:00 gcalctool yuriy 25624 0.0 0.0 10640 884 pts / 2 S + 10:21 0:00 grep --color = auto gcalctool

Here we are interested in the line: " yuriy 25609 7.6 0.4 500840 17964? Sl 10:20 0:00 gcalctool". 25609 is the PID of the gcalctool process.

There is another easier way to find out the PID of a process - this is pidof command, which takes a process name as a parameter and prints its PID. An example of executing the pidof command:

$ pidof gcalctool 25609

We "kill" the process with the kill command

When the PID of a process is known, we can kill it with the kill command... The kill command takes the PID of the process as a parameter. For example, let's kill the process with the number 25609:

Kill 25609

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

Kill -9 25609

The SIGTERM signal may not stop the process (for example, by catching or blocking the signal), while SIGKILL always kills the process, since it cannot be caught or ignored.

We kill processes with the killall command

Killall command in Linux it is designed to "kill" all processes with the same name. This is convenient since we don't need to know the PID of the process. For example, we want to close all processes named gcalctool. Run in terminal:

Killall gcalctool

The killall command, like kill, sends the SIGTERM signal by default. To send another signal, you need to use the option -s... For instance:

Killall -s 9 gcalctool

Conclusion

Some processes cannot be stopped as a regular user. For example, if the process was started as the root user or as another system user, then the kill and killall commands must be executed as the superuser, adding sudo (on Ubuntu):

Sudo kill 123

There are situations when you are working in a graphical interface (for example, GNOME) and you are unable to open a terminal emulator to stop a frozen process. Then you can switch to the virtual console with the keys Ctrl + Alt + F1, log into it and execute commands from there. And then go back by pressing Ctrl + Alt + F7.

You can get help on using any command with the man command:

Man ps man grep man pidof man kill man killall







2021 gtavrl.ru.