The KILL command is used to terminate the specified procedure (terminate a process) and is a common command for the unix/linux process. In general, when we need to terminate some or certain processes, we first apply the Ps/pidof/pstree/top and other objects to obtain the process PID, and then use the KILL command to kill the process. Another use of the KILL command is to send a beacon number to the specified procedure or process group (the command kill sends the specified signal to the specified process or processes group), or Determine if the process number is still in the PID process. For example, there are many applications that use the SIGHUP signal as a trigger to read the device files from scratch.
a common parameter
Format: Kill <pid>
Format: Kill-term <pid>
Send the sigterm signal to the specified procedure, and if the process does not capture the signal, the procedure terminates (if no signal is specified, the TERM signal is sent. The TERM signal'll kill processes which do don't catch this signal.)
Format: kill-l
Lists all the signal names (Print a list of signal names. These are found in/usr/include/linux/signal.h). Only the 9th kind of signal (SIGKILL) can terminate the process without preconditions, other signal process has the power to ignore. Here are the common signal numbers:
HUP 1 Terminal disconnected
INT 2 Interrupts (same Ctrl + C)
QUIT 3 exit (with Ctrl +)
TERM 15 terminated.
KILL 9 Forced termination
CONT 18 continued (contrary to stop, FG/BG command)
Stop 19 Pause (same Ctrl + Z)
Format: Kill-l <signame>
Displays the numeric value of the specified beacon number.
Format: kill-9 <pid>
Format: Kill-kill <pid>
Forced to kill the specified procedure, without preconditions, terminates the specified procedure.
Format: Kill%<jobid>
Format: kill-9%<jobid>
Kill the assigned task (use the Jobs command to list)
Format: Kill-quit <pid>
Format: kill-3 <pid>
Make the normal exit of the statutes.
Killall command
The killall command kills all processes within the same process group. It allows you to specify the name of the procedure to terminate, not the PID.
# Killall HTTPD
Second, the example
1 First Use PS to find the process, and then kill it with kill.
[Root@new55 ~]# Ps-ef|grep Vim
Root 3368 2884 0 16:21 pts/1 00:00:00 vim Install.log
Root 3370 2822 0 16:21 pts/0 00:00:00 grep vim
[Root@new55 ~]# Kill 3368
[Root@new55 ~]# Kill 3368
-bash:kill: (3368)-No process
third, kill signal
02 |
1) Sighup 2) SIGINT 3 Sigquit 4) Sigill |
03 |
5) Sigtrap 6) SIGABRT 7 Sigbus 8) SIGFPE |
04 |
9) SIGKILL SIGUSR1) SIGSEGV SIGUSR2 |
05 |
Sigpipe) sigalrm sigterm) Sigstkflt |
06 |
SIGCHLD) Sigcont SIGSTOP) SIGTSTP |
07 |
Sigttin) Sigttou Sigurg) sigxcpu |
08 |
SIGXFSZ) sigvtalrm sigprof) sigwinch |
09 |
Sigio) SIGPWR Sigsys) sigrtmin |
10 |
sigrtmin+1) sigrtmin+2 sigrtmin+3) sigrtmin+4 |
11 |
sigrtmin+5) sigrtmin+6 sigrtmin+7) sigrtmin+8 |
12 |
sigrtmin+9) sigrtmin+10 sigrtmin+11) sigrtmin+12 |
13 |
sigrtmin+13) (sigrtmin+14) sigrtmin+15) SIGRTMAX-14 |
14 |
SIGRTMAX-13) SIGRTMAX-12 SIGRTMAX-11) SIGRTMAX-10 |
15 |
SIGRTMAX-9) SIGRTMAX-8 SIGRTMAX-7) SIGRTMAX-6 |
16 |
SIGRTMAX-5) SIGRTMAX-4 SIGRTMAX-3) SIGRTMAX-2 |
17 |
) Sigrtmax SIGRTMAX-1) |
In the list, the signal numbered 1 ~ 31 is a traditional UNIX-supported signal that is unreliable (non-real time), and the signal numbered 32 to 63 is later expanded to call it a reliable signal (real-time signal). The difference between unreliable and reliable signals is that the former does not support queuing and may result in loss of signal, which does not.
below we discuss the signal that the number is less than sigrtmin.
1) Sighup
This signal is issued at the end of a user terminal connection (normal or abnormal), usually at the end of the control process of the terminal, notifying each job within the same session, when they are no longer associated with the control terminal.
When you log on to Linux, the system assigns a terminal (session) to the logged-on user. All programs running at this terminal, including foreground process groups and background process groups, are typically part of this session. When the user exits the Linux login, the foreground process group and the background have the process to the terminal output will receive the SIGHUP signal. The default action for this signal is to terminate the process, so the foreground process group and the process with terminal output in the background will be aborted. However, this signal can be captured, such as wget can capture the sighup signal, and ignore it, so that even if you quit the Linux login, wget can continue to download.
In addition, for daemons that are detached from the terminal, this signal is used to notify it to re-read the configuration file.
2) SIGINT
A program termination (interrupt) signal that is issued when the user types a intr character (usually ctrl-c) that notifies the foreground process group to terminate the process.
3) Sigquit
Similar to SIGINT, but controlled by quit characters (usually ctrl). A process produces a core file when it exits Sigquit, in the sense that it is similar to a program error signal.
4) Sigill
Illegal directives were executed. Typically, an error occurs in the executable itself, or an attempt is made to execute a data segment. This signal can also be generated when the stack overflows.
5) Sigtrap
Generated by a breakpoint instruction or other trap instruction. Used by debugger.
6) SIGABRT
Call the signal generated by the abort function.
7) Sigbus
Illegal address, including memory address alignment (alignment) error. For example, a four-word integer is accessed, but its address is not a multiple of 4. It differs from SIGSEGV in that the latter is triggered by illegal access to legitimate storage addresses (such as access that is not part of its own storage space or read-only storage).
8) Sigfpe
Emitted when a fatal arithmetic operation error occurs. This includes not only floating-point arithmetic errors, but also all other arithmetic errors such as overflow and divisor 0.
9) SIGKILL
Used to immediately end a program's operation. This signal cannot be blocked, processed, or ignored. If an administrator discovers that a process cannot be terminated, try sending the signal.
SIGUSR1)
Left to the user to use
One ) SIGSEGV
An attempt was made to access memory that was not assigned to itself, or to write data to a memory address that did not have write access.
) SIGUSR2
Left to the user to use
sigpipe)
The pipe is broken. This signal usually occurs during interprocess communication, such as two processes using FIFO (pipe) communication, the read pipe is not opened or accidentally terminated to the pipeline, write process will receive sigpipe signal. In addition, with socket communication two processes, write process in the write socket, the read process has been terminated.
) Sigalrm
Clock timing signal, calculated is the actual time or clock time. The alarm function uses this signal.
) Sigterm
Program end (terminate) signal, unlike Sigkill, the signal can be blocked and processed. Typically used to require the program to exit normally, the shell command kill defaults to generate this signal. If the process does not stop, we will try to Sigkill.
sigchld)
The parent process receives this signal at the end of the child process.
If the parent process does not process this signal, and there is no wait child process, the child process terminates, but also occupies the table entry in the kernel process table, where the subprocess is called the zombie process. In this case, we should avoid (the parent process either ignores the sigchild signal, or catches it, or wait for the subprocess it derives, or the parent process terminates first, when the termination of the child process is automatically taken over by the Init process).
) Sigcont
Let a stop (stopped) process continue. This signal cannot be blocked. You can use a handler to allow a program to perform a specific job when the stopped state becomes a continuation. For example, re-display the prompt ...
) SIGSTOP
Stop (stopped) the execution of the process. Notice the difference between it and terminate and interrupt: The process is not finished, it's just suspending execution. This signal cannot be blocked, processed or ignored.
) SIGTSTP
Stops a process from running, but the signal can be processed and ignored. The user types the Susp character characters (usually ctrl-z) to send this signal
) Sigttin
When a background job is to read data from a user terminal, all processes in the job receive a sigttin signal. By default, these processes will stop executing.
Sigttou)
Similar to Sigttin, but received when writing a terminal (or modifying terminal mode).
Sigurg)
Occurs when "emergency" data or Out-of-band data arrives at the socket.
) Sigxcpu
Exceeded CPU time resource limit. This restriction can be read/changed by Getrlimit/setrlimit.
) Sigxfsz
When the process attempts to enlarge the file, it exceeds the file size resource limit.
) Sigvtalrm
Virtual clock signal. Similar to SIGALRM, but calculates the CPU time consumed by the process.
) Sigprof
Similar to SIGALRM/SIGVTALRM, but includes the CPU time used for the process and the time of the system call.
sigwinch)
emitted when the window size changes.
Sigio)
The file descriptor is ready to begin an input/output operation.
) SIGPWR
Power failure
) Sigsys
An illegal system call.
In the signal listed above, the signal that the program cannot catch, block, or ignore is : sigkill,sigstop
The signal that cannot be restored to the default action is: Sigill,sigtrap
The default causes for a process abort are: Sigabrt,sigbus,sigfpe,sigill,sigiot,sigquit,sigsegv,sigtrap,sigxcpu,sigxfsz
the signal that the default will cause the process to exit is: Sigalrm,sighup,sigint,sigkill,sigpipe,sigpoll,sigprof,sigsys,sigterm,sigusr1,sigusr2,sigvtalrm
the signal that will cause the process to stop by default is : Sigstop,sigtstp,sigttin,sigttou
The default process ignores signals are: Sigchld,sigpwr,sigurg,sigwinch
In addition, the Sigio is exited in the SVR4, is ignored in 4.3BSD, and Sigcont continues when the process hangs, otherwise it is ignored and cannot be blocked.
In general, in the Linux shell
Ctrl-c is to send SIGINT signal, ctrl-z send sigstop signal ctrl-d not send signal, but represent a special binary value, indicating EOF
The specific system configuration can be viewed through stty-a, such as
# stty-a speed 38400 baud; Rows 35; Columns 166; line = 0; Intr = ^c; Quit = ^\; erase = ^?; Kill = ^u; EOF = ^d; EOL = <undef>; Eol2 = <undef>; Swtch = <undef>; start = ^q; stop = ^s; Susp = ^z; Rprnt = ^r; Werase = ^w; Lnext = ^v; flush = ^o; min = 1; Time = 0; -parenb-parodd CS8-HUPCL-CSTOPB CREAD-CLOCAL-CRTSCTS-CDTRDSR-IGNBRK-BRKINT-IGNPAR-PARMRK-INPCK-ISTRIP-INLCR- IGNCR icrnl Ixon-ixoff-iuclc-ixany-imaxbel-iutf8 opost-olcuc-ocrnl onlcr-onocr-onlret-ofill-ofdel nl0 cr0 tab0 Bs0 vt0 ff0 isig icanon iexten echo echoe echok-echonl-noflsh-xcase-tostop-echoprt echoctl Echoke
Common few: Kill-sigstop $pid # equivalent to Ctrl-z
Kill-sigcont $pid # equivalent to FG
Kill-sigint $pid # equals ctrl-c
In the script implementation can be used echo-e ' \00x ' or echo $ ' \00x ' #x表示十进制数 such as: Ctrl-a \001 ctrl-b with \002 ctrl-c \003 with ctrl-d ... ... Ctrl-z with \032
For example, to express ctrl-d, you can use Echo-e ' \004 '
How to use Shell to lose under the terminal ctrl+z,ctrl+c,ctrl+d and so on
I tried some of the ctrl-z, take the example of
Echo ^z
Echo-e "\0xx" #不知道ctrl-Z represents 0 a few
Echo-e "ALT+\0XX"
System (ECHO-E \ "\" 0xx "\")
Generally speaking:
Ctrl-c is to send the SIGINT signal,
Ctrl-z is sending the sigstop signal.
Instead of sending a signal, ctrl-d represents a special binary value that indicates EOF
Specifically you can stty-a view system settings
If you want to implement it in a script, for example:
Sleep &
pid=$!
Kill-sigstop $pid # equals ctrl-z
Kill-sigcont $pid # equivalent to FG
Kill-sigint $pid # equals ctrl-c