Shell learns 52 days----Delete process kill command

Source: Internet
Author: User

Control and deletion of processes

UseKillcommand to terminate a process.usually,terminating a foreground process can be usedCtrl + CKey,However, for a background process, you must use theKillcommand to terminate,we need to first usePs/pidof/pstree/topand other tools to get the processPID,then useKillcommand to kill the process.. Killcommand is to end the process by sending a specified signal to the process..in the default case,Take the number theof theTremSignal. termThe signal will terminate all processes that cannot acquire the signal..for those processes that can get the signal, use the number9of theKillSignal,forcibly"Kill" the process.

detailed kill command

1. Format :

Kill [ parameter ] [ process number , i.e. PID]

2. Function :

Sends the specified signal to the corresponding process.do not specify the model will be sentsifterm ()terminates the specified process.If you cannot terminate the process, you can use the"-kill" parameter,it sends a signal that isSIGKILL (9),the process will be forced to end,UsePScommand orJobscommand to view the process number. Rootusers will affect the user's process,Non-Rootusers can only affect their own processes.

3. Parameters

Parameters

Description

-L ( lowercase letter )

Signal , If the number parameter is not added , the "-L" parameter is used to list all signal names

-A

The current process of Lee is , does not limit the command name or process number of the corresponding relationship

-P

Specifies that the kill command prints only the process number of the related process without sending any signals

-S

Specify Send Signal

-U

Specify user

Note :

1.kill command can have signal number options Span style= "font-family: Arial" > can also be without If there's no signal, okay ,kill command will send a stop signal This signal can be captured by the process Yes, the process can clean up and release resources before it is launched can also be used kill send a specific signal to the process for example :

KILL-2 123// its effect is equivalent to running the PID at the foreground of the 123 process while pressing the CTRL + C key . but , Ordinary users can only use without Signal of the parameter Kill command or maximum use -9 Signal .

2.kill can have a process ID number as a parameter . when using Kill When you want these processes to send a signal , must be the master of these processes . If you attempt to revoke a process that does not revoke permissions or undo a non-existent process , you'll get an error message . .

3. You can signal to multiple processes or terminate them .

4. When kill successfully sends a signal , the shell displays the process's termination information on the screen . Sometimes this information is not displayed immediately , only when you press the Enter Key to make Shell when the command prompt appears again , before it shows up. .

5. It should be noted that,signal to force the process to terminate,this often brings some side effects .,If the data is lost, the terminal cannot return to the normal state.be careful when sending signals,only when there is a last resort,AdoptKillSignal(9),because the process cannot first capture it to undo all background Jobs,can enterkill 0.because some commands that run in the background start multiple processes,track and find all the processes that are going to be killed.PIDIt's a very troublesome thing..At this,UseKill 0to terminate all currentShellthe process started,It's an effective method..

4. Case studies

Case 1:

#kill-L// list all signal names

In the output , only the first 9 signals (SIGKILL) can terminate the process unconditionally , Other signal processes have the right to ignore . The following are commonly used signals :

Signal Name

Number

Description

HUP

1

Terminal disconnection

Int

2

Interrupt ( same as Ctrl + C)

QUIT

3

Exit ( with Ctrl)

Term

15

Terminate

KILL

9

Forced termination

CONT

18

Continue ( as opposed to STOP, fg/bg command )

STOP

19

Pause ( with Ctrl + Z)

Case 2: The value of the specified signal is obtained ( case insensitive )

#kill-L Term

15

#kill-L Kill

9

#kill-L SIGKILL

Case 3: use kill to kill process with PS command

#ps-ef | grep vim// get PID on vim process , For example, the pid obtained is 111

#kill 111// Delete vim process

Case 4: Kill the process completely

#kill-9 111

Case 5: Kill all processes of the specified user

#kill-9 $ (ps-ef| grep username)// method 1

#kill-u username// method 2

Case 6:init process (PID 1) is not to be killed

#kill-9 1

This is becauseInitis aLinuxone of the indispensable programs in the system.the so-calledInitProcess,He's a kernel-initiated user-level process.kernel self-booting(has been loaded into memory,Start Running,and has initialized all device drivers and data structures, etc.)after,just by starting a user-level programInitthe way,completing the boot process.so, InitA clock is the first process(its process number is always1).all other processes areInitdescendants of the process. Initthe process is not to be killed.not as it seemsInitthe role of the process is being gradually weakened.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Shell learns 52 days----Delete process kill command

Related Article

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.