Linux Command: Kill

Source: Internet
Author: User

Syntax format
Kill [-S Signal] [Program] or kill [-l signal]
Instructions for use

The kill command sends a signal (default, sigterm signal) to a running program. The default operation is generally to stop the process. If you want to stop a process, specify the process identifier (PID) in the processid variable ). This shell reports that each
PID of the running process (unless multiple processes are started on the same pipeline, in this case, shell reports the last process number ).
You can also use the ps command to find the process ID of the command. The root user can use the kill command to stop any process. If not
Root User, the process to be stopped must have been started. Signalname is identified in an uppercase/lowercase independent way,
No sig prefix. If the specified signalnumber is 0, the kill command checks the validity of the specified PID.

Main Parameters
-S {signalname | signalnumber} specifies the signal number or signal name. For example, specify-9 or kill for the sigkill signal.
-Signalname indicates a signal name, such as sighup.
-Signalnumber indicates the number of signals.

Note: In the syntax, use the default signal to specify the negative PID, which must be specified as a signal. Otherwise, the first operand is interpreted as a signalnumber. Processid specifies a decimal integer to represent a process or process group to be sent. If
PID is a positive value. The kill command sends a process with the same ID as the PID. If the PID value is 0, kill the command
Processes that send signals to all process groups whose IDs are the same as those of the sender process group. Do not send signals to processes whose PID is 0 or 1.
If the PID is-1, the kill command sends signals to all processes owned by valid users of the sender. If no signal is sent, the PID is 0.
Or 1 process. If the signal is not a negative value of-1, the kill command sends the signal to all processes whose ID is equal to the absolute value of PID in the process group.
-L lists the names of signals supported by the implementation. -Lexitstatus lists the signal names with the public sig prefix removed. If exitstatus
It is a decimal integer that corresponds to the signal name <br/> is displayed. If exitstatus is a signal corresponding
The exit status value of the terminated process. The name of the signal corresponding to the process to be terminated is displayed.

Application Instance

  • To stop a specified process, enter:
Kill 1095 stops the process by sending the default sigterm signal to process 1095.
NOTE: If process 1095 has made special arrangements to ignore or overwrite the sigterm signal, the process may not actually stop.
  • To stop several processes that ignore the default signal, enter:
Kill-kill 2098 this sending signal 9, that is, the sigkill signal, to process 1569 and 2098. The sigkill signal is
A special signal that cannot be ignored or overwritten.
  • To stop all processes and log off, enter:
Kill-kill 0 sends the signal 9, that is, the sigkill signal, to all the processes whose IDs are equal to the sender group ID.
Because the shell cannot ignore the sigkill signal, it also stops logging on to the shell and logs off the user.
  • To stop all processes owned by you, enter:
Kill-9-1 This sends the signal 9, which is the sigkill signal, to all processes owned by valid users, and even those on other workstations.
Processes that are started and belong to other Process Groups. If a list of your requests is being printed, it is also stopped.
  • To send a different signal to a process, enter:
The name of the kill-usr1 1103 kill command is misleading because many signals, including SIGUSR1, do not stop the process.
Operations that occur on the SIGUSR1 signal are defined by a specific running application. Note: send a signal 15, or use this
The form of the kill command to send the sigterm signal, must be explicitly specified-15 or term.

The process cannot be killed.

People who have worked in Linux development usually encounter a situation where a process cannot be killed. Even if the kill-9 method is used, the general teaching book only says that kill-9 can kill any process,

In this case, we will feel very contradictory. The other is also normal. Generally, there are two situations that cannot be killed:

First, the process has become a zombie process. When its parent process recycles it or kill its parent process, it will be invisible to the PS output;
Second, the process is in the kernel state. The Linux process runs in the kernel state and the user State. When the process enters the kernel state, all signals, including sigkil, are blocked,

Therefore, kill-9 becomes invalid at this time.

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.