您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页【神奇的 Linux】启动后台保持运行的进程

【神奇的 Linux】启动后台保持运行的进程

来源:伴沃教育

开始

文件描述符

  • 0 stdin 标准输入
  • 1 stdout 标准输出
  • 2 stderr 标准错误

重定向

echo "test" > temp.txt  # > 会覆盖已存在的文件
echo "test" >> temp.txt  # >> 会以累加的方式输出到文件
python hello.py < input.in  # 重定向到输入
python hello.py > output.out # 重定向到输出
python hello.py 2> error.err  # 重定向到错误输出
python hello.py 2>stderr.txt  1>stdout.txt # 输出分离 
python hello.py > output.txt 2>&1  # 输出合并 
python hello.py 2 > /dev/null  # 任何数据都会被丢弃到垃圾桶(位桶/黑洞)
python hello.py >/dev/null 2>&1  # 标准输出和标准错误 

进入正题

单一个& 是不够的,因为是终端启动的进程,那么该进程的父进程就是终端,所以终端关闭,子进程随着关闭。所以要用到 nohup 将进程的父进程设置为1的 init 进程 。

nohup python hello.py > out.log 2>&1 &

雾霾天 等风来

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务