Files
obsidian-vault/06 平台与配置/linux服务器中使用nohup命令保持进程后台运行.md
2026-06-23 00:24:32 +08:00

30 lines
802 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#linux #ubuntu #freqtrade #软件配置 #量化交易
```bash
# 启动
nohup python /path/to/your_strategy.py > /path/to/strategy.log 2>&1 &
# 记录 PID可选
echo $! > /tmp/strategy.pid
# 关闭
PID=$(cat /tmp/strategy.pid) # 或通过 ps 查找
kill $PID # 正常终止
kill -9 $PID # 强制终止(慎用)
```
上述代码记录了进程放入后台、查询PID、终止进程的方法。
```bash
ps aux | grep "进程名或关键词"
# 补充一个模糊查询进程PID的方法
# ps命令示例写法如上
```
示例:
```bash
# 运行 Python 脚本,日志保存到 app.log
nohup python3 data_analysis.py > app.log 2>&1 &
# 启动 SpringBoot 项目(带环境参数)
nohup java -jar usercenter.jar --spring.profiles.active=prod > usercenter.log 2>&1 & [6](@ref)
```