Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to kill a process under the Linux command line

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Positioning process

The step of killing an unresponsive process is to locate the process. There are two commands I use to locate processes: the top command and the ps command. Top is a tool that every system administrator knows, and with the top command, you can know which processes are currently running. On the command line, enter the top command to see the program process you are running (figure 1)

Figure 1: the top command gives you a lot of information.

You can see quite important information from the list displayed. For example, Chrome browsers are slow to respond. According to our top command, we can identify processes running in four Chrome browsers, with pid numbers of 3827, 3919, 10764 and 11679, respectively. This information is important and there is a special way to end the process.

Although the top command is convenient, it's not the most effective way to get the information you need. You know that the Chrome process you want to kill is that, and you don't want to see the real-time information displayed by the top command. For this reason, you can use the ps command and then use the grep command to filter out the output. This ps command displays a snapshot of the current process list, and then uses the grep command to output matching styles. The reason for filtering the output of the ps command through the grep command is simple: if you enter only the ps command, you will get a snapshot of the list of all current processes, and what we need is a list of Chrome browser processes. So the order looks like this:

Ps aux | grep chrome

The aux option here is as follows:

A = shows the progress of all users

U = display the user and owner of the process

X = also shows processes that are not attached to the terminal

This x parameter is important when you search for information about graphical programs.

When you enter the above command, you will get more information than figure 2, and it is sometimes more efficient to use than the top command.

Figure 2: use the ps command to locate the required content information.

End the process

Now let's start the task of ending the process. We have two kinds of information that can help us kill the wrong process.

The name of the process

ID (PID) of the process

Which one you use will determine how terminal commands are used, and there are usually two commands to end the process:

Kill-end the process through the process ID

Killall-end the process by its name

There are two different signals that can be sent to these two commands to end the process. The signal you send determines the result you want from the end process command. For example, you can send a HUP signal to the command to end the process, which will actually restart the process. When you need to restart a process immediately (for example, in the case of a daemon), this is a wise choice. You can get a list of all the signals by typing kill-l, and you will find a large number of signals.

Figure 3: available end process signals.

The most frequently used signal to end a process is:

Signal NameSingle ValueEffectSIGHUP1 suspend SIGINT2 keyboard interrupt signal SIGKILL9 sends out kill signal SIGTERM15 sends out stop signal SIGSTOP17, 19, 23 stop the process

The good thing is, you can use the signal value instead of the signal name. So you don't have to remember all kinds of signal names.

So let's now kill the Chrome browser process with the kill command. The structure of this command is:

Kill SIGNAL PID

Where SIGNAL is the signal to be sent, and PID is the ID of the process being killed. We already know that the ps command from us shows that the process ID numbers we want to end are 3827, 3919, 10764, and 11679. So to send a signal to end the process, we enter the following command:

Kill-9 3827 kill-9 3919 kill-9 10764 kill-9 11679

Once we enter the above command, all processes in the Chrome browser will be killed successfully.

We have an easier way! If we already know the name of the process we want to kill, we can use the killall command to send the same signal, like this:

Killall-9 chrome

Incidentally, the above command may not capture all running Chrome processes. If, after running the above command, you enter the ps aux | grep chrome command to filter and see which of the remaining Chrome processes are running, the way to * is to return to the kIll command to end the process by sending a signal value of 9 through the process ID.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report