【发布时间】:2021-07-08 16:33:19
【问题描述】:
我正在尝试杀死 ubuntu 18.04 中的某个进程,为此我正在使用 pkill 命令。但由于某种原因,我能够压制Killed 消息。
这是正在运行的进程。
# ps -a
PID TTY TIME CMD
2346 pts/0 00:00:00 gunicorn
2353 pts/0 00:00:00 sh
2360 pts/0 00:00:00 gunicorn
2363 pts/0 00:00:00 gunicorn
2366 pts/0 00:00:00 ps
我试图终止进程并抑制日志
# 1st attempt
# pkill -9 gunicorn 2>&1 /dev/null
pkill: only one pattern can be provided
Try `pkill --help' for more information.
#2nd attempt (This killed process but got output `Killed` and have to press `enter` to get into command line)
# pkill -9 gunicorn > /dev/null
root@my-ubuntu:/# Killed
#3rd attempt(behavior similar to previous attempt)
# pkill -9 gunicorn 2> /dev/null
root@my-ubuntu:/# Killed
root@my-ubuntu:/#
我错过了什么?
【问题讨论】:
-
重定向可能是
>/dev/null 2>&1,意思是1>/dev/null 2>&1,写成2>&1 /dev/null,/dev/null被当作一个参数(还要注意重定向顺序很重要)。否则>& /dev/null -
@NahuelFouilleul 我也试过
pkill -9 gunicorn >& /dev/null。但无法消除Killed消息。 -
相关:stackoverflow.com/questions/81520/… 和 stackoverflow.com/questions/5719030/… 在子外壳 @987654335@ 或当前外壳 @987654336@
-
顺便说一句,最好配置 gunicorn 来创建 pid 文件(添加选项
-p file.pid),然后通过该文件中的 pid 杀死它