MacOS 中使用 killall & kill

本文详细介绍了在MacOS中如何使用killall和kill命令来终止进程。killall可以直接通过进程名称杀死进程,而kill需要指定进程的PID。提到了killall的-v参数以显示详细执行信息,以及kill的-s参数用于指定发送的信号。还讨论了进程的用户ID和信号的相关知识,并给出了一些实用的实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

**前言:**终止一个前台进程可以使用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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值