Linux kill command Learning

Source: Internet
Author: User
Tags pkill

The following content is reproduced from http:// OS .51cto.com/art/200910/158639.htm

1. Kill
Purpose: kill a process based on the process number.
Usage: Kill [signal code] process ID
Example:
[Root @ localhost ~] # Ps auxf | grep httpd
Note: Kill-9 to force termination and exit
Example [root @ localhost ~] # Ps aux | grep Gaim
Or [root @ localhost ~] # Pgrep-l Gaim 5031 Gaim
5031 Gaim
[Root @ localhost ~] # Kill-9 5031
Special usage:
Kill-stop [pid]
Send sigstop (17,19, 23) to stop a process without killing the process in Linux.
Kill-cont [pid]
Send sigcont (, 25) to start a stopped process again.
Kill-kill [pid]
Send sigkill (9) to force the process to stop immediately without cleaning.
Kill-9-1
Terminate all processes you have.

2. killall
Purpose: directly kill all processes by program name
Usage: name of the program that is running killall
Example:
[Root @ localhost beinan] # pgrep-l Gaim 2979 Gaim
[Root @ localhost beinan] # killall Gaim
Note: This command can use the-9 parameter to force the process to be killed.

3. pkill
Purpose: directly kill all processes by program name
Usage: # Name of the running program
Example:
[Root @ localhost beinan] # pgrep-l Gaim 2979 Gaim
[Root @ localhost beinan] # pkill Gaim

4. xkill
Purpose: Kill the desktop graphic interface program.
Application Scenario example: When Firefox crashes and cannot exit, you can click the mouse to kill Firefox.
When xkill is running and the icon of the personal brain is displayed, it will be okay if any graphics program crashes.
If you want to terminate xkill, right-click to cancel it;
Call method:
[Root @ localhost ~] # Xkill

◆ Note:
Killall
Name)
Killall-kill a process by name in Linux
Synopsis (Overview)
Killall [-egiqvw] [-signal] Name...
Killall-l
Killall-V
Description)
Killall sends a signal to all processes that run any specified command. If no signal name is specified, it sends sigterm ..
The signal can be specified by name (such as-hup) or number (such as-1). The signal 0 (check whether the process exists) can only be specified by number.
If the command name includes a slash (/), the process executing the specific file will be killed, which is irrelevant to the process name.
If no process can be killed for the commands listed, killall returns a non-zero value. If at least one process is killed for each command, killall returns 0. The killall process will never kill itself (but it can kill other killall processes ).

Options)

-E requires exact matching for long names. if a command name is longer than 15 characters, the entire name may not be used (overflow ). in this case, killall will kill all processes that match the first 15 characters of the name. with the-E Option, such records will be ignored. if the-V option is specified, killall prints a message for each ignored record.

-G kills the process that belongs to the process group. The kill signal is sent only once to each group, even if the same process group contains multiple processes.

-I interaction method: Ask for confirmation information before killing a process in Linux.

-L list all known signal names.

-If no process is killed, Q will not complain.

-V indicates whether the report signal is successfully sent.

-V displays the version information.

-W waits for all killed processes to die. killall checks whether any killed process still exists once per second and returns only when all the processes are dead. note: If the signal is ignored or does not work, or the process stays in the zombie state, killall may wait permanently.

Files)
The location of the/proc file system.
Known bugs (known bugs)
Killing files only takes effect for executable files that have been opened during execution. That is, a hybrid executable file cannot be killed in this way.
It should be warned that the input of killall name may not produce the expected results on non-Linux systems, especially when privileged users perform the operation with caution.
In the gap between the two scans, if the process disappears and is replaced by a new process with the same PID, killall-W cannot detect it.

Signal list

$ Kill-L1) sighup 2) SIGINT 3) sigquit 4) sigill5) sigtrap 6) SIGABRT 7) sigbus 8) sigfpe9) sigkill 10) SIGUSR1 11) SIGSEGV 12) sigusr213) sigpipe 14) sigalrm 15) sigterm 16) sigstkflt 17) sigchld18) sigcont 19) sigstop 20) sigtstp 21) sigttin22) sigttou 23) sigurg 24) sigxcpu 25) signature) sigvtalrm 27) sigprof 28) sigwinch 29) sigio30) sigpwr 31) sigsys 34) sigrtmin 35) sigrtmin + 136) sigrtmin + 2 37) sigrtmin + 3 38) sigrtmin + 4 39) sigrtmin + 540) sigrtmin + 6 41) sigrtmin + 7 42) sigrtmin + 8 43) sigrtmin + 944) sigrtmin + 10 45) sigrtmin + 11 46) sigrtmin + 12 47) sigrtmin + 1348) sigrtmin + 14 49) sigrtmin + 15 SIGRTMAX-14 51) SIGRTMAX-1352 (SIGRTMAX-12) SIGRTMAX-11 53) SIGRTMAX-10 54) SIGRTMAX-956 (SIGRTMAX-8) SIGRTMAX-7 57) SIGRTMAX-6 58) SIGRTMAX-560 59) SIGRTMAX-4) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-164) sigrtmax

List, numbered 1 ~ The 31 signal is a traditional Unix-supported signal, which is an unreliable signal (non-real-time) numbered 32 ~ The 63 signal was expanded later, called a reliable signal (real-time signal ). The difference between unreliable and reliable signals is that the former does not support queuing and may cause signal loss, while the latter does not.

Below we will discuss the signal number smaller than sigrtmin.

1) sighup
This signal is sent at the end of the user terminal connection (normal or abnormal). Generally, when the control process of the terminal ends, it notifies all jobs in the same session, they are no longer associated with control terminals.

When you log on to Linux, the system assigns a session to the login user ). All programs running on this terminal, including foreground and background process groups, generally belong to this session. When you log out of Linux, processes in the frontend process group and in the background that are output to the terminal will receive a sighup signal. The default operation for this signal is to terminate the process. Therefore, the Process with terminal output in the frontend and backend will be aborted. However, this signal can be captured. For example, wget can capture the sighup signal and ignore it. In this way, even if you log out of Linux, wget can continue downloading.

In addition, this signal is used to notify the daemon that is out of the relationship with the terminal to re-read the configuration file.

2) SIGINT
The interrupt signal is sent when you type the intr character (usually Ctrl-C) to notify the foreground process group to terminate the process.

3) sigquit
Similar to SIGINT, but controlled by the quit character (usually Ctrl-\). A process generates a core file when it exits because it receives a sigquit exit. In this sense, it is similar to a program error signal.

4) sigill
The execution of invalid commands is usually caused by errors in the executable file, or the attempt to execute data segment. Stack Overflow may also generate this signal.

5) sigtrap
Generated by breakpoint commands or other trap commands. Used by debugger.

6) SIGABRT
The signal generated by calling the abort function.

7) sigbus
Invalid Address, including memory address alignment error. For example, you can access an integer with four characters in length, but its address is not a multiple of 4. It differs from SIGSEGV in that the latter is triggered by illegal access to valid storage addresses (for example, access does not belong to your own bucket or read-only bucket ).

8) sigfpe
When a fatal arithmetic operation error occurs, it includes not only floating point operation errors, but also overflow and Division 0 and other arithmetic errors.

9) sigkill
It is used to immediately end the running of the program. This signal cannot be blocked, processed, or ignored. If the Administrator finds that a process cannot be terminated, he can try to send this signal.

10) SIGUSR1
Reserved for users

11) SIGSEGV
Try to access the memory not allocated to you, or try to write data to the memory address that has no write permission.

12) sigusr2
Reserved for users

13) sigpipe
Pipe rupture. This signal is usually generated during inter-process communication. For example, for two processes that use FIFO (pipeline) Communication, the read pipeline is written to the pipeline if it is not opened or unexpectedly terminated, and the write process receives the sigpipe signal. In addition, when writing a socket to two processes that communicate with a socket, the read process is terminated.

14) sigalrm
The scheduled clock signal is used to calculate the actual time or clock time. The alarm function uses this signal.

15) sigterm
The program terminate signal. Unlike sigkill, the signal can be blocked and processed. It is usually used to require the program to exit normally. 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 for the child process (wait), although the child process terminates, it still occupies a table item in the kernel table, at this time, sub-processes are called Zombie processes. In this situation, we should avoid (parent process, ignore sigchild signal, capture it, or wait, its derived child process, or the parent process is terminated first, at this time, the termination of the sub-process is automatically taken over by the INIT process ).

18) sigcont
Let a stopped process continue execution. this signal cannot be blocked. A handler can be used to allow a program to complete a specific job when it changes from the stopped state to the continue execution. for example, re-display the prompt...

19) sigstop
Stop (stopped) process execution. Note the difference between it and terminate and interrupt: the process has not ended, but is paused. This signal cannot be blocked, processed, or ignored.

20) sigtstp
The process is stopped, but the signal can be processed and ignored. This signal is sent when you type the susp character (usually Ctrl-Z ).

21) sigttin
When a background job reads data from a user terminal, all processes in the job receive the sigttin signal.

22) sigttou
Similar to sigttin, but received when writing terminal (or modifying terminal mode.

23) sigurg
"Urgent" data or out-of-band data is generated when it reaches the socket.

24) sigxcpu
The CPU time limit is exceeded. This limit can be read/changed by getrlimit/setrlimit.

25) sigxfsz
When a process attempts to expand a file so that it exceeds the file size resource limit.

26) sigvtalrm
The virtual clock signal is similar to sigalrm, but the CPU time occupied by the process is calculated.

27) sigprof
Similar to sigalrm/sigvtalrm, but includes the CPU time used by the process and the time when the system calls it.

28) sigwinch
Window size changed.

29) sigio
The file descriptor is ready for input/output operations.

30) sigpwr
Power failure

31) sigsys
Invalid system call.

Among the Signals listed above, signals that cannot be captured, blocked, or ignored by the program are: sigkill, sigstop
Signals that cannot be restored to the default action include: sigill and sigtrap.
By default, the signals that cause process abortion include: SIGABRT, sigbus, sigfpe, sigill, sigiot, sigquit, SIGSEGV, sigtrap, sigxcpu, sigxfsz
By default, the process exits with the following signals: sigalrm, sighup, SIGINT, sigkill, sigpipe, sigpoll, sigprof, sigsys, sigterm, SIGUSR1, sigusr2, and sigvtalrm.
By default, the signal that causes the process to stop is: sigstop, sigtstp, sigttin, sigttou
Signals ignored by default include sigchld, sigpwr, sigurg, and 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.

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.