**前言:**终止一个前台进程可以使用Ctrl+C组合键,但是结束一个后台进程就须用 kill 命令来实现。
kill
命令是通过向进程发送指定的信号来结束相应进程的。在默认情况下,采用编号为 15 的TERM
信号。TERM 信号将终止所有不能捕获该信号的进程。对于那些可以捕获该信号的进程就要用编号为 9 的 kill 信号,强行“杀掉”该进程。
killall 杀死指定名字的进程
关闭 iTunes 程序(需要注意区分大小写): killall iTunes
killall 参数解释
man killall 读取官方说明:
因为网上查到的资料都比较旧,内容也千篇一律,有些命令都已经淘汰了,所以我直接晒出最新官方说明来讲。
NAME
killall -- kill processes by name
SYNOPSIS
killall [-delmsvz] [-help] [-u user] [-t tty] [-c procname] [-SIGNAL]
[procname ...]
DESCRIPTION
The killall utility kills processes selected by name, as opposed to the
selection by pid as done by kill(1). By default, it will send a TERM
signal to all processes with a real UID identical to the caller of
killall that match the name procname. The super-user is allowed to kill
any process.
The options are as follows:
-v Be more verbose about what will be done.
-e Use the effective user ID instead of the (default) real
user ID for matching processes specified with the -u option.
-help Give a help on the command usage and exit.
-l List the names of the available signals and exit, like in kill(1).
-m Match the argument procname as a (case sensitive) regular expression
against the names of processes found.
CAUTION! This is dangerous, a single dot will match
any process running under the real UID of the caller.
-s Show only what would be done, but do not send any signal.
-d Print detailed information about the processes matched, but do not send any signal.
-SIGNAL Send a different signal ins