惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Last Watchdog
The Last Watchdog
博客园_首页
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
美团技术团队
小众软件
小众软件
V
V2EX
博客园 - Franky
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
Attack and Defense Labs
Attack and Defense Labs
S
Security Affairs
Simon Willison's Weblog
Simon Willison's Weblog
I
Intezer
T
The Exploit Database - CXSecurity.com
有赞技术团队
有赞技术团队
S
Schneier on Security
人人都是产品经理
人人都是产品经理
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
K
Kaspersky official blog
PCI Perspectives
PCI Perspectives
AI
AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客
O
OpenAI News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The Register - Security
The Register - Security
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
博客园 - 【当耐特】
C
Cisco Blogs
大猫的无限游戏
大猫的无限游戏
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
S
Securelist
Application and Cybersecurity Blog
Application and Cybersecurity Blog
P
Proofpoint News Feed
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
L
LangChain Blog
SecWiki News
SecWiki News
博客园 - 叶小钗
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V2EX - 技术
V2EX - 技术
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
L
LINUX DO - 热门话题
Cisco Talos Blog
Cisco Talos Blog

mephisto.cc

修复rime-ice无法弹出候选框的问题 开机滚动字体显示优化 个人网站安全防护 树莓派上部署Vaultwarden 使用goaccess实时分析Caddy日志 个人网站监控 Hugo全站AVIF记 Linux下尝试使用Godot开发小游戏 Arch linux dae 透明代理 Airflow接管galler-dl下载任务 如何使用gallery-dl批量下载图像 Arch核显下如何愉快玩Dota2和CS2 Arch/labwc 环境网络相关设置 Rime添加dota2词库 Arch 重装记录 Supertuxkart iOS版终于发布了 打造自己的流媒体音乐服务 剪切板管理工具clipcat推荐 MangoHud性能监控 微信小程序开发记 Rofi试用 解决Arch下VSCode无法输入中文的问题 独立窗口管理器下无法录屏问题处理 上海市二手房成交数据监控 OpenLDAP监控 Arch linux如何顺畅连接蓝牙设备 使用Git和Ansible管理配置文件 Arch Linux SSL VPN 客户端配置 简单获取celery任务实时结果 Arch linux下iNode客户端的安装和使用方法 券商费率调整记 迷你主机组装记 Labwc更换定制皮肤 树莓派跑分流代理 实用自动代理配置示例 九年老鼠标复活记 Openvpn示例 Mac下如何旋转webp图片 如何隐藏Vscode中Markdown PDF插件的头部内容 解决Linux下网络配置无法变更保存的问题 labwc环境启用wlogout Ubuntu下新官方微信尝鲜 简单检测用户是否开启广告屏蔽 Atuin ZFS下卡顿问题解决 Wine安装64位微信 Fish 和 Atuin使用记 Fastapi简单实现临时下载链接 Fastapi微信公众号开发简要 Hugo根据语种展示不同内容 如何修复Waybar微信图标错误 信封加密简要 Linux环境下维护公众号记录 快速隐藏和呼出终端 Wayland环境自动切换壁纸 SuperTuxKart 试玩 简单抓取雪球股票快讯 Wine安装微信保姆教程 Hysteria科学上网简要 Ubuntu 23.10 钉钉无法启动解决方法 网站导航栏防止插入Adsense自动广告 Linux环境按键检测 Hugo文末添加最后修改时间 Wayland环境ksnip无法复制问题解决 我眼中的股票市场 Caddy简单图片防盗链 greetd和regreet使用教程 Wayland环境下截图加后期修改 Wayland 环境下gif录屏 Firefox的一些有趣功能 Ubuntu 切换系统语言 Firefox 标题栏高度调整 网站添加回到顶部功能 Hugo自定义字体 Labwc 便捷配置 Wofi使用教程 窗口管理器labwc使用记 文件共享软件Dufs推荐 Hugo静态站点接入Adsense广告 Fcitx5配置详解 Ubuntu安装chrome的方法总结 一种Xterm.js的全屏方案 Google网址收录api Python示例 手机听离线音乐 Snipe it资产导入 应用启动器yofi使用配置 Snipe it资产管理系统安装使用 Ubuntu开机启动加速 Vue3 vite TypeScript跨域等相关设置 Ubuntu手动升级Libreoffice Ubuntu设置alacritty为默认终端 简体文章批量转换为繁体 使用Inkscape调整svg图片大小 实用命令 使用mitmproxy给手机app抓包 Python中rstrip方法细解 Github同主机多仓库部署deploy key问题处理 Linux安装最新版本Python KeePassXC使用教程 Ubuntu 22.10连接蓝牙耳机报错br-connection-profile-unavailable解决方法 Caddy日志配置轮转和格式化
为什么你的kill命令不能列出信号表
2023-11-15 · via mephisto.cc

有时候你想用 kill 命令给某些程序发送特殊信号,一时之间你不知道信号名、编号或者怕拼写错误,,此刻 kill 命令自带的 kill -l 或者 kill -L 命令或许能帮到你。

部分读者可能遇到这种状况:

1➜  ~ kill -l
2HUP INT QUIT ILL TRAP IOT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH POLL PWR SYS
3➜  ~ kill -L
4kill: unknown signal: SIGL
5kill: type kill -l for a list of signals

看上面的输出:

  • kill -l 也只是显示个简单列表,没有编号;

  • kill -L 居然会报错;

这一切很有可能是你用了 zsh

1➜  ~ echo $SHELL
2/usr/bin/zsh

如果你切换到 bash,熟悉的界面就回来了。

 1mephisto@pc:~$ kill -l
 2 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL       5) SIGTRAP
 3 6) SIGABRT      7) SIGBUS       8) SIGFPE       9) SIGKILL     10) SIGUSR1
 411) SIGSEGV     12) SIGUSR2     13) SIGPIPE     14) SIGALRM     15) SIGTERM
 516) SIGSTKFLT   17) SIGCHLD     18) SIGCONT     19) SIGSTOP     20) SIGTSTP
 621) SIGTTIN     22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
 726) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO       30) SIGPWR
 831) SIGSYS      34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
 938) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
1043) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
1148) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
1253) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
1358) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
1463) SIGRTMAX-1  64) SIGRTMAX
15mephisto@pc:~$ kill -L
16 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL       5) SIGTRAP
17 6) SIGABRT      7) SIGBUS       8) SIGFPE       9) SIGKILL     10) SIGUSR1
1811) SIGSEGV     12) SIGUSR2     13) SIGPIPE     14) SIGALRM     15) SIGTERM
1916) SIGSTKFLT   17) SIGCHLD     18) SIGCONT     19) SIGSTOP     20) SIGTSTP
2021) SIGTTIN     22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
2126) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO       30) SIGPWR
2231) SIGSYS      34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
2338) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
2443) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
2548) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
2653) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
2758) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
2863) SIGRTMAX-1  64) SIGRTMAX

为什么会这样呢? 请看下面的输出(zsh 环境)。

1➜  ~ type -a kill
2kill is a shell builtin
3kill is /usr/bin/kill
4kill is /bin/kill
5➜  ~ md5sum /usr/bin/kill /bin/kill
6bec5c7ac875a475f103603d8170dbc31  /usr/bin/kill
7bec5c7ac875a475f103603d8170dbc31  /bin/kill
8➜  ~ echo $SHELL
9/usr/bin/zsh

目前 bash 和 zsh 都有 builtin 的 kill 命令(优先级高,率先命中),相关文档说明:

当你在 bashzsh 中使用 kill 命令时,优先命中的都是 shell 自带的 kill 命令,二者的输出差异导致上述不同。

独立的 kill 命令 可使用 /bin/kill 调用(在笔者机器上,/usr/bin/kill 是相同程序,md5 码相同):

1➜  ~ /bin/kill -l
2HUP INT QUIT ILL TRAP ABRT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT
3CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH POLL PWR SYS
4➜  ~ /bin/kill -L
5 1 HUP      2 INT      3 QUIT     4 ILL      5 TRAP     6 ABRT     7 BUS
6 8 FPE      9 KILL    10 USR1    11 SEGV    12 USR2    13 PIPE    14 ALRM
715 TERM    16 STKFLT  17 CHLD    18 CONT    19 STOP    20 TSTP    21 TTIN
822 TTOU    23 URG     24 XCPU    25 XFSZ    26 VTALRM  27 PROF    28 WINCH
929 POLL    30 PWR     31 SYS

输出正常,比 bash 内置的编号少(少了 31 以上的)。

原始信号定义在这两个头文件中 /usr/include/asm/signal.h/usr/include/asm/siginfo.h

 1  ~ cat /usr/include/linux/signal.h
 2/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 3#ifndef _LINUX_SIGNAL_H
 4#define _LINUX_SIGNAL_H
 5
 6#include <asm/signal.h>
 7#include <asm/siginfo.h>
 8
 9#define SS_ONSTACK      1
10#define SS_DISABLE      2
11
12/* bit-flags */
13#define SS_AUTODISARM   (1U << 31)      /* disable sas during sighandling */
14/* mask for all SS_xxx flags */
15#define SS_FLAG_BITS    SS_AUTODISARM
16
17#endif /* _LINUX_SIGNAL_H */

看看头文件:

 1 ~ head -n 62 /usr/include/asm/signal.h
 2/_ SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note _/
 3#ifndef \_ASM_X86_SIGNAL_H
 4#define \_ASM_X86_SIGNAL_H
 5
 6#ifndef **ASSEMBLY**
 7#include <linux/types.h>
 8#include <linux/time.h>
 9
10/_ Avoid too many header ordering problems. _/
11struct siginfo;
12
13/_ Here we must cater to libcs that poke about in kernel headers. _/
14
15#define NSIG 32
16typedef unsigned long sigset_t;
17
18#endif /_ **ASSEMBLY** _/
19
20#define SIGHUP 1
21#define SIGINT 2
22#define SIGQUIT 3
23#define SIGILL 4
24#define SIGTRAP 5
25#define SIGABRT 6
26#define SIGIOT 6
27#define SIGBUS 7
28#define SIGFPE 8
29#define SIGKILL 9
30#define SIGUSR1 10
31#define SIGSEGV 11
32#define SIGUSR2 12
33#define SIGPIPE 13
34#define SIGALRM 14
35#define SIGTERM 15
36#define SIGSTKFLT 16
37#define SIGCHLD 17
38#define SIGCONT 18
39#define SIGSTOP 19
40#define SIGTSTP 20
41#define SIGTTIN 21
42#define SIGTTOU 22
43#define SIGURG 23
44#define SIGXCPU 24
45#define SIGXFSZ 25
46#define SIGVTALRM 26
47#define SIGPROF 27
48#define SIGWINCH 28
49#define SIGIO 29
50#define SIGPOLL SIGIO
51/_
52#define SIGLOST 29
53_/
54#define SIGPWR 30
55#define SIGSYS 31
56#define SIGUNUSED 31
57
58/_ These should not be considered constants from userland. _/
59#define SIGRTMIN 32
60#define SIGRTMAX \_NSIG

各种信号的详细解释请看帮助文档,里面解释的比较到位,包括实时信号的相关介绍。

常用信号:

  • HUP 1 终端挂断
  • INT 2 中断(同 Ctrl + C)
  • QUIT 3 退出(同 Ctrl + \)
  • KILL 9 强制终止
  • TERM 15 终止(Default action is to terminate the process)
  • CONT 18 继续(与 STOP 相反,fg/bg 命令)
  • STOP 19 暂停(同 Ctrl + Z)

KILL 编号 9,好比游戏里面的无可奈何、放终极大招了。

CONT/STOP 读者可以简单测试下,控制 yes、tail 等命令的输出,还挺有趣的。

TERM 信号是默认的,通常程序收到该信号后,会触发相关代码,做一些收尾动作,然后退出,即所谓的优雅退出。

比如 k8s:

Typically, with this graceful termination of the pod, kubelet makes requests to the container runtime to attempt to stop the containers in the pod by first sending a TERM (aka. SIGTERM) signal, with a grace period timeout, to the main process in each container. The requests to stop the containers are processed by the container runtime asynchronously. There is no guarantee to the order of processing for these requests. Many container runtimes respect the STOPSIGNAL value defined in the container image and, if different, send the container image configured STOPSIGNAL instead of TERM. Once the grace period has expired, the KILL signal is sent to any remaining processes, and the Pod is then deleted from the API Server. If the kubelet or the container runtime's management service is restarted while waiting for processes to terminate, the cluster retries from the start including the full original grace period.

各个软件处理信号并不一致,Nginx 就有所不同,它的优雅关闭是发送 SIGQUIT 😅:

1nginx -s <SIGNAL>
2
3where <SIGNAL> can be one of the following:
4
5    quit – Shut down gracefully (the SIGQUIT signal)
6    reload – Reload the configuration file (the SIGHUP signal)
7    reopen – Reopen log files (the SIGUSR1 signal)
8    stop – Shut down immediately (or fast shutdown, the SIGTERM singal)

再比如 gunicorn,符合套路,常规出牌的:

 1
 2Master process
 3
 4    QUIT, INT: Quick shutdown
 5    TERM: Graceful shutdown. Waits for workers to finish their current requests up to the graceful_timeout.
 6    HUP: Reload the configuration, start the new worker processes with a new configuration and gracefully shutdown older workers. If the application is not preloaded (using the preload_app option), Gunicorn will also load the new version of it.
 7    TTIN: Increment the number of processes by one
 8    TTOU: Decrement the number of processes by one
 9    USR1: Reopen the log files
10    USR2: Upgrade Gunicorn on the fly. A separate TERM signal should be used to kill the old master process. This signal can also be used to use the new versions of pre-loaded applications. See Upgrading to a new binary on the fly for more information.
11    WINCH: Gracefully shutdown the worker processes when Gunicorn is daemonized.

这让人想起显示软件版本有的 -v-V--verson-version,每次都很感慨,只能说世界是丰富多彩的。

伟人安慰语:

“吾生也有涯,而知也無涯” -- 莊子