Kill command in CentOS to close the process

Source: Internet
Author: User

Kill command in CentOS to close the process

The safest way to kill a process is to simply use the kill command without a modifier or a flag.

First, use the ps-ef command to determine the PID of the process to be killed, and then enter the following command:
# Kill-pid

Note: Standard kill commands can achieve the goal. Terminate the problematic process and release the process resources to the system. However, if a child process is started and only the parent process is killed, the child process is still running and consumes resources. To prevent these so-called "zombie processes", ensure that all child processes are killed before the parent process is killed.

Determine the PID or PPID of the process to be killed
# Ps-ef | grep httpd

End the process in an elegant way
# Kill-l PID

The-l option tells the kill command to end the process as if the user who started the process had logged out. When this option is used, the kill command also tries to kill the left child process. But this command is not always successful-you may still need to manually kill the child process and then kill the parent process.

TERM Signal
Send a TERM signal to the parent process, trying to kill it and its child process.
# Kill-TERM PPID

Killall command
Killall command to kill all processes in the same process group. It allows you to specify the name of the process to be terminated, rather than the PID.

# Killall httpd

Stop and restart Processes
Sometimes you only want to simply stop and restart the process. As follows:
# Kill-HUP PID
This command causes Linux to shut down the slow execution process and then restart immediately. This command is convenient when you configure the application. You can execute this command when you need to restart the process after modifying the configuration file.

When using the linux operating system, it is inevitable that you encounter some software "Shelling" problems. In this case, you need to use the powerful kill command in linux to end the related processes. This is extremely easy in linux. You only need to kill xxx. Here xxx represents the process PID number related to the software running.
First, we need to use another ps command in linux to find the process-related PID Number: ps aux | grep program_filter_word
Ps a shows all programs under the current terminal, including those of other users.
Ps-A shows all programs.
When listing programs in ps c, the real command name of each program is displayed without the path, parameter, or resident service identifier.
The effect of this parameter is the same as that of the specified "A" parameter.
When listing programs, ps e displays the environment variables used by each program.
Ps f uses ASCII characters to display the tree structure and express the relationship between programs.
The ps-H tree structure is displayed, indicating the relationship between programs.
Ps-N displays all programs except the programs under the ps command terminal.
Ps uses the program signal format to display the program status.
When listing programs in ps, it includes interrupted subroutines.
Ps-t <terminal number> specifies the terminal number and lists the program status of the terminal.
Ps u displays the program status in user-based format.
Ps x shows all programs, not distinguished by terminals.
The most common method is ps aux. Then, use the grep command in the pipeline to filter out specific processes, and then perform operations on specific processes.
Second, run the kill command to end the process: kill xxx
1) Role
The kill command is used to stop a process.
2) Format
Kill [-s signal |-p] [-a] pid...
Kill-l [signal]
3) Parameters
-S: Specifies the sent signal.
-P: analog transmission signal.
-L: Name List of the specified signal.
Pid: ID of the process to be aborted.
Signal: indicates the Signal.
4) Description
Process is a very important concept in Linux. Linux is a multi-task operating system that often runs multiple processes at the same time. We don't care about how these processes are allocated, or how the kernel manages the allocation of time slices. We care about how to control these processes so that they can serve users well.
The Linux operating system includes three different types of processes, each of which has its own characteristics and attributes. An interactive process is a process started by a Shell. Interactive processes can run either on the foreground or on the background. The batch processing process is a process sequence that is not associated with the terminal. The monitoring process (also known as the system daemon process) is a process started when the Linux system is started and runs in the background. For example, httpd is a monitoring process of the famous Apache server.
The kill command works by sending a system operation signal and the process ID of a program to the Linux kernel. Then, the system kernel can operate the process specified by the process ID number. For example, in the top command, we can see that the system runs many processes, sometimes we need to use kill to stop some processes to improve system resources. When explaining the installation and login commands, I mentioned that the role of multiple virtual consoles in the system is to switch to other virtual consoles to close the program when a program error causes a system deadlock. In this case, the command is kill, because kill can be directly called by most internal Shell commands.
5) Application Instances
(1) force stop (often used to kill) a process with the process ID 324:
# Kill-9 324
(2) Remove the deadlock in Linux
In Linux, a program crashes and is in a deadlock state. In this case, you do not need to restart the computer. You only need to stop (or close) the problematic program. When kill is on the X-Window interface, the main program (except the crashed program) is generally started normally. Open a terminal and stop the problematic program there. For example, if the Mozilla browser program is locked, you can use the kill command to stop all programs that contain the Mozolla browser. First, use the ps command to find the PID of the program, and then use the kill command to stop the program:
# Kill-SIGKILL XXX
XXX indicates the process ID of the program with the Mozolla browser.
(3) Use commands to recycle memory
We know that memory is very important to the system. memory recovery can improve system resources. The kill command can be used to abort some programs that are out of track or do not have the corresponding programs for a long time. For example, if you use the top command to find a useless (Zombie) process, you can use the following command:
# Kill-9 XXX
XXX is a useless process ID.
Run the following command:
# Free
The available memory capacity is increased.
(4) killall command
In Linux, A killall command is also provided to directly use the process name instead of the process ID number. For example:
# Killall-HUP inetd

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.