Kill command in linux

Source: Internet
Author: User

Linux kill command Summary 1. The kill command is used to stop a process. 2. Format: kill [-s signal |-p] [-a] pid... kill-l [signal] 3. Parameter-s: Specifies the signal to be sent. -P: analog transmission signal. -L: Name List of the specified signal. Pid: ID of the process to be aborted. Signal: indicates the Signal. 4. process description 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. Processes started when the Linux system is started when the monitoring process (also known as the system daemon process) is running 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 Instance (1) force stop (often used to kill) a process with the process ID 324: # kill-9 324 (2) 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 top command to investigate the PID of the program, and then use the kill command to stop the program: # kill-sigkill xxx, where XXX is the process ID of the program containing the Mozolla browser. (3) Use commands to reclaim 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 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 run the following command: # kill-9 XXX, where XXX is a useless process ID. Run the following command: # free, and the available memory capacity is increased. (4) The killall command is also provided in Linux. You can directly use the process name instead of the process ID number, for example: # killall-HUP inetd * the safest way to kill a process is to simply use the kill command without a modifier or 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: the Standard kill command can usually 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. Optional * determine the PID or PPID of the process to be killed # ps-ef | grep httpd finished * end the process in an elegant way # kill-l PID-l option tells the kill command to start the process as if it were to end the process. 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. ------------------------------------------------------------------------------ * The TERM signal sends a TERM signal to the parent process, trying to kill it and its Child processes. # Kill-term ppid -------------------------------------------------------------------------------- * killall command kills 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 -------------------------------------------------------------------------------- * you only need to stop and restart the process. Run the following command: # kill-hup pid to shut down Linux's slow execution process and restart it 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. Killer * kill-9 PID-approved kill-s SIGKILL this powerful and dangerous Command forces the process to terminate suddenly at runtime, and the process cannot be self-cleaned after it ends. The hazard is that the system resources cannot be released normally. It is generally not recommended unless other methods are ineffective. When using this command, you must use ps-ef to confirm that no zombie process is left. Only the parent process can be terminated to eliminate zombie processes. If the zombie process is adopted by init, the problem will be 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 occupies a large amount of system resources, you need to restart the machine at some time to clear the process.

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.