我正在尝试终止 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:/#
我错过了什么?
答案 0 :(得分:0)
我想你想要这个语法:
pkill -9 gunicorn &>/dev/null
&>
是 Bash 中较新的添加项(想想 4.0 ??),它是重定向 stdout 和 stderr 的速记方式。
此外,您是否在启动 gunicorn 的同一终端会话中运行 pkill
?我不认为 pkill
会打印像“Killed”这样的消息,这让我怀疑这是否来自其他进程......
您可以通过在终端中运行 set +m
来抑制它(禁用作业监控)。要重新启用,请运行 set -m
。