我有一个脚本forever.py
,我想在后台一直运行(之后我关闭了连接到虚拟机的终端)。我使用nohup python3 forever.py &
,它的工作,但问题是,几天后它崩溃(我猜由于内存溢出),我需要再次手动重新启动它。为了解决这个问题,我按照这里的建议,创建了一个bash.sh
文件,其中包含:
#!/bin/bash
until python3 forever.py; do
echo "'forever.py' crashed with exit code $?. Restarting..." 2>stderr.txt
sleep 1
done
,在终端中运行命令:nohup bash bash.sh &
目前运行良好,我希望它重启时,程序崩溃。
我的问题是:我如何停止执行这个?我试过pkill nohup
,但它不起作用!
建议更多地研究pkill
命令:
pkill -9 -x "forever.py"