The difference between linux ubuntu kill instruction and kill instruction

Refer to Article 1: kill and kill -- kill processes Refer to Article 2: how to use the kill and kill commands to stop a ...
usage
System signal
Find running processes

Refer to Article 1: kill and kill -- kill processes

Refer to Article 2: how to use the kill and kill commands to stop a process

Reference article 3: using kill and kill commands to manage processes on Linux | Linux China

Kill is a tool that terminates processes running on a system based on names. Kill terminates the process based on the process ID number (PID). Kill and kill can also send specific system signals to processes.

Use kill and kill and ps to manage and end stuck or unresponsive processes. In this tutorial, replace [process name] with the name of the process you want to terminate in each example.

usage

How to use kill

The kill command takes the following form:

killall [process name]

Kill will terminate all programs that match the specified name. Kill sends a SIGTERM signal that terminates a running process that matches the specified name. You can specify different signals using the following - s option:

killall -s 9 [process name]

This sends a SIGKILL signal, and you can also specify the signal in one of the following formats:

killall -KILL [process name] killall -SIGKILL [process name] killall -9 [process name]

How to use kill

The kill Command terminates each process specified by its PID.

The command takes the following form:

kill [PID]

If there are no other options, kill sends SIGTERM to the specified PID and requires the application or service to shut down itself.

Multiple PIDs and standby system signals can be specified in one kill command. The following examples send SIGKILL signals to the specified PID:

kill -s KILL [PID] kill -KILL [PID]

System signal

The kill command does not directly terminate the process. On the contrary, a signal is sent to the process. If the process receives a given signal, the process will have corresponding instructions. Further references to all available signals are provided on the man pages:

man 7 signal
Standard signals Linux supports the standard signals listed below. Several signal numbers are architecture-dependent, as indicated in the "Value" column. Where three values are given, the first one is usually valid for alpha and sparc, the middle one for x86, arm, and most other architectures, and the last one for mips. (Values for parisc are not shown; see the Linux kernel source for signal numbering on that architecture.) A dash (-) denotes that a signal is absent on the corresponding architecture. ​ First the signals described in the original POSIX.1-1990 standard. ​ Signal Value Action Comment ────────────────────────────────────────────────────────────────────── SIGHUP 1 Term Hangup detected on controlling terminal or death of controlling process SIGINT 2 Term Interrupt from keyboard SIGQUIT 3 Core Quit from keyboard SIGILL 4 Core Illegal Instruction SIGABRT 6 Core Abort signal from abort(3) SIGFPE 8 Core Floating-point exception SIGKILL 9 Term Kill signal SIGSEGV 11 Core Invalid memory reference SIGPIPE 13 Term Broken pipe: write to pipe with no readers; see pipe(7) SIGALRM 14 Term Timer signal from alarm(2) SIGTERM 15 Term Termination signal SIGUSR1 30,10,16 Term User-defined signal 1 SIGUSR2 31,12,17 Term User-defined signal 2 SIGCHLD 20,17,18 Ign Child stopped or terminated SIGCONT 19,18,25 Cont Continue if stopped SIGSTOP 17,19,23 Stop Stop process SIGTSTP 18,20,24 Stop Stop typed at terminal SIGTTIN 21,21,26 Stop Terminal input for background process SIGTTOU 22,22,27 Stop Terminal output for background process ​ The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.

Simply list all available signals without their descriptions:

kill -l killall -l
[root@RV1126_RV1109:~]# kill -l 1) HUP 2) INT 3) QUIT 4) ILL 5) TRAP 6) ABRT 7) BUS 8) FPE 9) KILL 10) USR1 11) SEGV 12) USR2 13) PIPE 14) ALRM 15) TERM 16) STKFLT 17) CHLD 18) CONT 19) STOP 20) TSTP 21) TTIN 22) TTOU 23) URG 24) XCPU 25) XFSZ 26) VTALRM 27) PROF 28) WINCH 29) POLL 30) PWR 31) SYS 32) RTMIN 64) RTMAX

If you need to convert a signal name to a signal number, or a signal number to a signal name, use the following example:

$ kill -l 9 KILL ​ $ kill -l kill 9

Find running processes

Use utilities like htop or top to view a real-time list of processes and their consumption of system resources. (my arm linux has no htop command!!!)

Use the ps command to view the currently running process and its pid. The following example uses grep to filter the list of all processes currently running for the string mediaserver: (with or without string symbols seems to be ok...)

[root@RV1126_RV1109:~]# ps -aux | grep mediaserver root 690 0.0 0.3 6084 3040 pts/0 S 13:53 0:02 ipc-daemon --no-mediaserver root 741 8.6 10.0 655072 87580 pts/0 Sl 13:53 4:59 mediaserver -c /oem/usr/share/mediaserver/rv1109/ipc.conf root 996 0.0 0.0 2056 224 pts/2 S+ 14:51 0:00 grep mediaserver [root@RV1126_RV1109:~]#

The number listed in the second column on the left is PID and 690 in the mediaserver process. The grep process always matches itself for a simple search, just like the second result.

be careful
You can use the command ps auxf to view a hierarchical tree of all running processes.

After obtaining the PID or process name, use kill or kill to terminate the above process.

Another option to find the PID is pgrep.

[root@RV1126_RV1109:~]# pgrep mediaserver 741

Verification process termination
Adding the - w option to the Kill Command will cause kill to wait for the process to terminate before exiting. Consider the following command:

killall -w irssi

This example sends the SIGTERM system signal to a background process whose name matches irssi. Kill will wait for the matching process to end. If no process matches the specified name, kill will return an error message:

$ killall -w irssi irssi: no process found

But why is mine like this???

[root@RV1126_RV1109:~]# killall -w mediaserver killall: bad signal name 'w' [root@RV1126_RV1109:~]# [root@RV1126_RV1109:~]# killall -w irssi killall: bad signal name 'w'

11 November 2021, 05:58 | Views: 8963

Add new comment

For adding a comment, please log in
or create account

0 comments