In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Linux kill command parameters and example analysis, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Kill command is used to terminate a specified process (terminate a process). It is a common command for process management under Unix/Linux. In general, when we need to terminate a process or processes, we first apply objects such as ps/pidof/pstree/top to obtain the process PID, and then apply the kill command to kill the process. Another use of the kill command is to send a signal (The command kill sends the specified signal to the specified process or process group) to a specified procedure or process group, or to determine whether a process whose procedure number is PID is still there. For example, there are many methods that use SIGHUP signals as a trigger for reading device files from scratch.
A commonly used parameter
Format: kill
Format: kill-TERM
Sends a SIGTERM signal to the specified procedure, and if the procedure does not capture the signal, the procedure terminates (If no signal is specified, the TERM signal is sent. The TERM signal will kill processes which do not catch this signal.)
Format: kill-l
List all signal names (Print a list of signal names. These are found in / usr/include/linux/signal.h). Only the ninth signal (SIGKILL) can terminate the process without precondition, and other signal processes have the right to ignore it. Here are the commonly used signals:
HUP 1 terminal disconnected
INT 2 interrupt (same as Ctrl + C)
QUIT 3 exit (same as Ctrl +)
TERM 15 termination
KILL 9 forced termination
CONT 18 continues (as opposed to STOP, fg/bg command)
STOP 19 pause (same as Ctrl + Z)
Format: kill-l
Displays the value of the specified signal.
Format: kill-9
Format: kill-KILL
Force to kill the specified process and terminate the specified process without precondition.
Format: kill%
Format: kill-9%
Kill the specified task (can be listed with jobs command)
Format: kill-QUIT
Format: kill-3
Make the Dharma exit normally.
Killall command
The killall command kills all processes in the same process group. It allows you to specify the name of the procedure to be terminated instead of PID.
# killall httpd
2. Examples
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)-there is no such process
III. Kill signal
01$ kill-l021) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGPIPE 14) SIGALRM 16) SIGSTKFLT0617) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP0721 22) SIGTTOU 23) SIGURG 24) SIGXFSZ 26) SIGVTALRM 28) SIGWINCH0929) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN1035 SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+3 40) SIGRTMIN+41139 41) SIGRTMIN+5 42) SIGRTMIN+5 44) SIGRTMIN+5 45) ) SIGRTMIN+11 46) SIGRTMIN+121347 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-141451 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-101555) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-61659) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-21763) SIGRTMAX-1 64) SIGRTMAX
In the list, the signal numbered 1-31 is supported by traditional UNIX and is unreliable (non-real-time), while the signal numbered 32-63 is later expanded and called reliable signal (real-time signal). The difference between an unreliable signal and a reliable signal is that the former does not support queuing, which may cause signal loss, while the latter does not.
Let's discuss the signal whose number is less than SIGRTMIN.
1) SIGHUP
This signal is sent at the end of the user terminal connection (normal or abnormal), usually at the end of the control process of the terminal, notifying each job in the same session, when they are no longer associated with the control terminal.
When logging in to Linux, the system assigns a terminal (Session) to the logged-in user. All programs running on this terminal, including foreground process group and background process group, generally belong to this Session. When the user logs out of Linux, the foreground process group and the process with output to the terminal in the background will receive the SIGHUP signal. The default operation of this signal is to terminate the process, so the process with terminal output in the foreground and background will be aborted. However, you can capture this signal, for example, wget can capture the SIGHUP signal and ignore it, so that even if you log out of the Linux login, wget can continue to download.
In addition, for daemons that are disconnected from the terminal, this signal is used to tell it to reread the configuration file.
2) SIGINT
A program termination (interrupt) signal that is sent when the user types an INTR character (usually Ctrl-C) to notify the foreground process group to terminate the process.
3) SIGQUIT
Similar to SIGINT, but controlled by QUIT characters (usually Ctrl-). The process generates a core file when it receives a SIGQUIT exit, which is similar to a program error signal in this sense.
4) SIGILL
Illegal instructions were carried out. It is usually due to an error in the executable itself or an attempt to execute a data segment. This signal can also be generated when the stack overflows.
5) SIGTRAP
Generated by breakpoint instructions or other trap instructions. Used by debugger.
6) SIGABRT
The signal generated by calling the abort function.
7) SIGBUS
Illegal address, including memory address alignment (alignment) error. For example, access to a four-word integer whose 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 does not belong to its own storage space or read-only storage space).
8) SIGFPE
Issued when a fatal arithmetic error occurs. It includes not only floating-point arithmetic errors, but also all other arithmetic errors such as overflows and divisor 0.
9) SIGKILL
It is used to end the running of the program immediately. This signal cannot be blocked, processed or ignored. If the administrator finds that a process cannot be terminated, try to send this signal.
10) SIGUSR1
Leave it to the user
11) SIGSEGV
Try to access memory that is not allocated to you, or try to write data to a memory address that does not have write permission.
12) SIGUSR2
Leave it to the user
13) SIGPIPE
The pipe is broken. This signal is usually generated in inter-process communication, such as two processes using FIFO (pipeline) communication. If the read pipeline is not opened or terminated unexpectedly, the write process will receive the SIGPIPE signal. In addition, the two processes that communicate with Socket, the write process, the read process has been terminated while writing the Socket.
14) SIGALRM
Clock timing signal, which calculates the actual time or clock time. The alarm function uses this signal.
15) SIGTERM
Program end (terminate) signal, unlike SIGKILL, which can be blocked and processed. It is usually used to require the program to exit normally, and the shell command kill generates this signal by default. If the process cannot be terminated, we will try SIGKILL.
17) SIGCHLD
When the child process ends, the parent process receives this signal.
If the parent process does not process this signal and does not wait the child process, the child process terminates, but it still occupies the table item in the kernel process table, and the child process is called a zombie process. This situation should be avoided (the parent process either ignores the SIGCHILD signal, or captures it, or wait its derived child process, or the parent process terminates first, where the termination of the child process is automatically taken over by the init process).
18) SIGCONT
Allow a stopped (stopped) process to continue. This signal cannot be blocked. You can use a handler to get a program to do specific work when it changes from stopped state to continue execution. For example, redisplay the prompt.
19) SIGSTOP
Stop the execution of the stopped process. Note the difference between it and terminate and interrupt: the process is not finished, it is just paused. This signal cannot be blocked, processed or ignored.
20) SIGTSTP
Stop the process, but the signal can be processed and ignored. This signal is sent when the user types the SUSP character (usually Ctrl-Z)
21) SIGTTIN
When a background job reads data from a user terminal, all processes in the job receive SIGTTIN signals. By default, these processes stop execution.
22) SIGTTOU
Similar to SIGTTIN, but received when writing to a terminal (or modifying terminal mode).
23) SIGURG
"urgent" data or out-of-band data is generated when it arrives at socket.
24) SIGXCPU
CPU time resource limit exceeded. This limit can be read / changed by getrlimit/setrlimit.
25) SIGXFSZ
When the process attempts to expand the file so as to exceed the file size resource limit.
26) SIGVTALRM
Virtual clock signal. Similar to SIGALRM, but calculates the CPU time consumed by the process.
27) SIGPROF
Similar to SIGALRM/SIGVTALRM, but including the CPU time used by the process and the time of system calls.
28) SIGWINCH
Issued when the window size changes.
29) SIGIO
The file descriptor is ready to start input / output operations.
30) SIGPWR
Power failure
31) SIGSYS
Illegal system call.
Among the signals listed above, the signals that cannot be captured, blocked or ignored by the program are: SIGKILL,SIGSTOP
The signals that cannot be restored to the default action are: SIGILL,SIGTRAP
By default, the signal that causes the process to abort is: SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGIOT,SIGQUIT,SIGSEGV,SIGTRAP,SIGXCPU,SIGXFSZ
The default signal that causes the process to exit is: SIGALRM,SIGHUP,SIGINT,SIGKILL,SIGPIPE,SIGPOLL,SIGPROF,SIGSYS,SIGTERM,SIGUSR1,SIGUSR2,SIGVTALRM
The default signal that causes the process to stop is: SIGSTOP,SIGTSTP,SIGTTIN,SIGTTOU
The signals ignored by the default process are: SIGCHLD,SIGPWR,SIGURG,SIGWINCH
In addition, SIGIO exits in SVR4 and is ignored in 4.3BSD; SIGCONT continues when the process is suspended, otherwise it is ignored and cannot be blocked.
After reading the above, have you mastered the parameters of the kill command in linux and the method of example analysis? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.