The Linux command summary kill command detailed

Source: Internet
Author: User

2. Use

The KILL command is used to abort a process.

2. Format
3. Parameters
-S: Specifies the signal to send. -P: Analog send signal. -L: Specifies a list of names for the signal. PID: The ID number of the process to abort. Signal: Indicates a signal.
4. Description

Processes are a very important concept in a Linux system. Linux is a multitasking operating system that often runs multiple processes at the same time. We don't care how these processes are distributed or how the kernel manages the allocation of time slices, and the concern is how to control these processes so that they can serve the user well.

The Linux operating system consists of three different types of processes, each of which has its own characteristics and attributes. An interactive process is a process that is initiated by a shell. The interactive process can be run either in the foreground or in the background. The batch process and terminal are not linked, and are a sequence of processes. The monitoring process (also known as the System daemon) is the process that is started when the Linux system starts and runs in the background. For example, HTTPD is the well-known Apache server monitoring process.

the KILL command works by sending a system operation signal to the kernel of the Linux system and the process identification number of a program, and then the system kernel can operate on the processes specified by the process identification number. For example, in the top command, we see that the system runs many processes, and sometimes it needs to use kill to abort some processes to improve system resources. When explaining the installation and landing commands, it was mentioned that the function of multiple virtual consoles is to switch to another virtual Console to shut down the program when a program error causes the system to deadlock. The command that is used at this point is kill, because Kill is a direct call to most shell internal commands.

5. Application examples

(1) Forcibly abort (often used to kill) a process with an identification number of 324:

(2) Unlocking the Linux system deadlock
In Linux, there are times when a program crashes and is in a deadlock state. You do not have to restart your computer at this time, just abort (or shut down) the problematic program. When Kill is in the X-window interface, the main program (except for the crashing program) normally starts. At this point, open a terminal, where the problematic program is aborted. For example, if the Mozilla browser program has a deadlock situation, you can use the KILL command to abort all programs that contain the Mozolla browser. First use the top command to investigate the PID of the program, and then use the KILL command to stop the program:

(3) Use the command to reclaim memory
We know that memory is very important to the system, and reclaiming memory can improve system resources. The KILL command can be used in a timely manner to abort some "deviant" programs or for a long time without corresponding programs. For example, using the top command to discover a useless (Zombie) process, you can use the following command:

Then use the following command:

(4) Killall command
Linux also provides a killall command that can directly use the name of the process rather than the process identification number, for example:

First use the PS-EF command to determine the PID to kill the process, and then enter the following command:

Note: A standard KILL command usually achieves its purpose. Terminate the problematic process and release the resources of the process to the system. However, if a process starts a child process and kills only the parent process, the child process is still running and therefore consumes resources. To prevent these so-called "zombie processes," Be sure to kill all of their child processes before killing the parent process.

-------------------------------------------------------------------------- ------* Determine the PID or Ppid # Ps-ef to kill the process | grep httpd--------------------------------------------------------------------------------* End process in an elegant way # kill-l PID The-l option tells the kill command to end the process in a way that appears to the user who started the process logged off. When this option is used, the kill command also attempts to kill the left child process. But this command is not always successful--you may still need to manually kill the child process before killing the parent process. --------------------------------------------------------------------------------*term Signal to the parent process to send a term signal, Trying to kill it and its child processes. # kill-term PPID--------------------------------------------------------------------------------*killall command The killall command kills all processes within the same process group. It allows you to specify the name of the process to terminate, not the PID. # killall httpd--------------------------------------------------------------------------------* Stop and restart process Sometimes you just want to simply stop and restart the process. The following: # kill-hup PID This command shuts down the Linux gentle execution process and then restarts immediately. This command is handy when configuring the application, which can be executed when the configuration file is modified to restart the process. --------------------------------------------------------------------------------* Lore kill-9 PID 

The same kill-s SIGKILL

This powerful and dangerous command forces the process to terminate abruptly at run time, and the process cannot clean itself up after the end. A hazard is a system resource that is not normally released, and is generally not recommended unless other methods are invalid.

When using this command, be sure to confirm with ps-ef that there are no zombie processes left. The zombie process can be eliminated only by terminating the parent process. If the zombie process is adopted by INIT, the problem is more serious. Killing the init process means shutting down the system.

If there is a zombie process in the system, and its parent process is init, and the zombie process consumes a lot of system resources, then you need to restart the machine at some point to clear the process table.

The Linux command summary kill command detailed

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.