Kill-Terminate process/Send signal of the Linux command I used

Source: Internet
Author: User
Tags builtin terminates

Description of Use

The KILL command terminates the specified process (terminate a process) and is a common command for process management under Unix/linux. In general, we use tools such as ps/pidof/pstree/top to get the process PID when we need to terminate some or some processes, and then use the KILL command to kill the process. Another use of the KILL command is to send a signal to the specified process or process group (the command kill sends the specified signal to the specified process or process group), or determine Whether the process number is PID is still in progress. For example, there are many programs that use the SIGHUP signal as a trigger condition for re-reading a configuration file.

In bash, the kill command is a shell built-in command, why? There are two reasons: for the first reason, bash can perform task management (&,ctrl+z,bg,fg,kill%jobid, etc.), and if Kill is just an external command, it can be difficult to terminate a task because the task is associated with the terminal, in turn, If the kill command is a shell built-in command, it is convenient to kill the specified task in the form of Kill%jobid (which seems to be not quite enough); the second reason is more important, if you want to kill a process and start a child process named Kill. So when the number of processes allowed to create is limited, even the kill process itself can not be created, but also how to kill other processes! (Kill is a shell builtin for the reasons:it allows job IDs to being used instead of process IDs, and, if you have reached th e limit on processes so you can create, and you don ' t has to start a process to kill another one.)

Common parameters

Format: Kill <pid>

Format: Kill-term <pid>

Sends a sigterm signal to the specified process, and if the process does not capture the signal, the process terminates (if no signal is specified, and the term signal is sent. The term signal would kill processes which do not catch this signal.)

Format: kill-l

Lists all signal names (Print a list of signal names. These is found in/usr/include/linux/signal.h). Only the 9th signal (SIGKILL) can terminate the process unconditionally, other signal processes have the right to ignore. The following are commonly used signals:

HUP 1 terminal disconnection
INT 2 Interrupt (with Ctrl + C)
Quit 3 exit (with Ctrl + \)
Term 15 termination
Kill 9 Forced termination
CONT 18 Continuation (contrary to stop, FG/BG command)
Stop 19 paused (with Ctrl + Z)

Format: Kill-l <signame>

Displays the value of the specified signal.

Format: kill-9 <pid>

Format: Kill-kill <pid>

Forces the specified process to be killed and terminates the specified process unconditionally.

Format: Kill%<jobid>

Format: kill-9%<jobid>

Kill the specified task (can be listed using the jobs command)

Using the exampleExample what type of command is a KILL command

[[email protected] ~]# type-a kill
Kill is a shell builtin
Kill Is/bin/kill
Kill Is/usr/bin/kill

[email  protected] ~]# help kill  
Kill:kill [-S Sigspec |-n Signum |-S IGSPEC] PID | Jobspec. or kill-l [Sigspec]
    Send The processes named by PID (or jobspec) the signal SIGSPEC.&N Bsp If
    Sigspec is not present, then SIGTERM was assumed.  an argument of '-l '
    ; Lists the signal names; If arguments follow '-l ' they is assumed to
    is signal numbers for which names should be LISTED.&NB Sp Kill is a shell
    builtin for the reasons:it allows job IDs to be used instead of
&NBSP;&NBSP;&N Bsp Process IDs, and, if you have reached the limit in processes that
    you can create, you don ' t has to Start a process to kill another one.

[Email protected] ~]#

Example two lists all signal names

[Email protected] ~]#kill-l
1) SIGHUP 2) SIGINT 3) Sigquit 4) Sigill
5) SIGTRAP 6) SIGABRT 7) Sigbus 8) SIGFPE
9) SIGKILL) SIGUSR1 SIGSEGV) SIGUSR2
Sigpipe) sigalrm SIGTERM) Sigstkflt
SIGCHLD) Sigcont SIGSTOP) SIGTSTP
) (Sigttin) Sigttou () Sigurg) sigxcpu
SIGXFSZ) sigvtalrm sigprof) sigwinch
SIGIO) SIGPWR Sigsys) sigrtmin
(sigrtmin+1) (sigrtmin+2) sigrtmin+3) sigrtmin+4
sigrtmin+5) sigrtmin+6 sigrtmin+7) sigrtmin+8
sigrtmin+9) (sigrtmin+10) sigrtmin+11) sigrtmin+12
sigrtmin+13) (sigrtmin+14) sigrtmin+15) SIGRTMAX-14
SIGRTMAX-13) SIGRTMAX-12-SIGRTMAX-11) SIGRTMAX-10
SIGRTMAX-9) SIGRTMAX-8 () SIGRTMAX-7) SIGRTMAX-6
SIGRTMAX-5) SIGRTMAX-4 () SIGRTMAX-3) SIGRTMAX-2
SIGRTMAX-1) Sigrtmax
[Email protected] ~]#

/usr/include/linux/signal.h wrote #define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define Sigill 4
#define SIGTRAP 5
#define SIGABRT 6
#define Sigiot 6
#define Sigbus 7
#define SIGFPE 8
#define SIGKILL 9
#define SIGUSR1 10
#define SIGSEGV 11
#define SIGUSR2 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIGSTKFLT 16
#define SIGCHLD 17
#define Sigcont 18
#define SIGSTOP 19
#define SIGTSTP 20
#define Sigttin 21
#define Sigttou 22
#define Sigurg 23
#define SIGXCPU 24
#define SIGXFSZ 25
#define SIGVTALRM 26
#define SIGPROF 27
#define Sigwinch 28
#define SIGIO 29
#define Sigpoll SIGIO
/*
#define SIGLOST 29
*/
#define SIGPWR 30
#define SIGSYS 31
#define Sigunused 31

/* These should not being considered constants from Userland. */
#define SIGRTMIN 32
#define SIGRTMAX _nsig

Example three gets the value of the specified signal

[[email protected] ~]# kill-l kill
9
[Email protected] ~]# kill-l SIGKILL
9
[Email protected] ~]# kill-l term
15
[Email protected] ~]# kill-l SIGTERM
15
[Email protected] ~]#

Example four init processes are not to be killed!

Init is one of the most indispensable programs in Linux system operation. The so-called Init process, which is a user-level process initiated by the kernel. After the kernel has booted itself (already loaded into memory, started running, and has initialized all device drivers and data structures, etc.), the boot process is completed by starting a user-level program init. As a result, Init is always the first process (its process number is always 1). All other processes are descendants of the INIT process.

[Email protected] ~]# kill-hup 1
[Email protected] ~]# kill-9 1
[Email protected] ~]# Kill-kill 1

the system is still running.
[Email protected] ~]#

Example five first use PS to find the process, and then kill it with kill

[Email protected] ~]# 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
[Email protected] ~]# kill 3368
[Email protected] ~]# kill 3368
-bash:kill: (3368)-No that process
[Email protected] ~]#

Example six kills a specified task

[Email protected] ~]#tail-f Install.log
Yue Reinstall scim-bridge-gtk-0.4.5-9.el5.i386
Yue Reinstall scim-pinyin-0.5.91-16.el5.i386
Yue Reinstall scim-chewing-0.3.1-11.el5.i386
Yue Reinstall scim-chinese-standard-0.0.2-1.el5.i386
Yue Reinstall scim-tables-0.5.6-7.i386
Yue Reinstall scim-qtimm-0.9.4-5.i386
Yue Reinstall scim-tables-chinese-0.5.6-7.i386
Yue Reinstall Fonts-chinese-3.02-12.el5.noarch
Yue Reinstall isdn4k-utils-3.2-56.el5.i386
Yue Reinstall stardict-2.4.5-5.i386
Ctrl + Z
[1]+ Stopped tail-f Install.log
[Email protected] ~]#Kill%1
[Email protected] ~]#Kill%1
-bash:kill: (3379)-No that process
[1]+ has terminated tail-f Install.log
[Email protected] ~]#

Kill-Terminate process/Send signal of the Linux command I used

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.