Linux后台执行命令

使用&符号(后台运行)

  • python3 script.py &(后台运行,退出终端时进程会终止)

使用nohup(不挂断运行)

  • nohup python3 script.py > script.log 2>&1 &(后台运行,退出终端后继续运行)
    • >  script.log 2>&1 = &> script.log
  • 2>&1:将 stderr、stdout都输出到script.log

使用setsid(创建新终端)

  • setsid python3 script.py &(创建新终端、放在后台运行)

需要完善的启动、监控、日志、重启服务:使用systemd 或 supervisor

posted @ 2025-12-19 11:26  Fēngwèi  阅读(1)  评论(0)    收藏  举报