我正在尝试使用pkill
和触发 Nginx 主进程的重新加载sudo
。
服务器重新加载正常,但我很好奇是否有人知道为什么该命令sudo pkill -HUP -f "nginx: master process"
返回代码 129?
# Running as root
$ pkill -HUP -f "nginx: master process"
$ echo $?
# Output is as expected:
0
# Running as a user (sudo is set to not prompt for a password)
% sudo pkill -HUP -f "nginx: master process
% echo $?
# Output is weird (considering sudo should be passing along the return
# code of the command it is executing):
129
Run Code Online (Sandbox Code Playgroud)
在 EC2 上运行的 Ubuntu 12.04.1 LTS 上运行......令人惊讶的是,在物理计算机(未使用云映像安装)上运行的 Ubuntu 12.04.1 LTS 运行良好。
通常,当 shell 返回 128 以上的状态码时,表示进程被信号杀死。减去 128 得到信号编号。您的 kill 命令被信号 1 终止,即 HUP。
pkill
注意永远不要自杀。但它匹配其父sudo
进程。
有几种方法可以避免这种情况:
pkill -x
仅考虑完全匹配而不是子字符串(如果可能,建议使用,这是避免虚假匹配的最佳方法)。-f
选项。"[n]ginx: master process"
.