目录

ssh连接服务器后台运行程序-Python程序为例

目录

ssh连接服务器后台运行程序—Python程序为例

使用nohup即可实现断开ssh连接命令也不会被终止。nohup: no hang up.

# 在后台运行test.py的python脚本
nohup python test.py &

nohup: ignoring input and appending output to ’nohup.out’上面命令运行日志默认输入到nohup.out文档中

nohup python test.py > test.log 2>&1 &

其中: >表示将标准输出(STDOUT)重定向到test.log文件;

2>&1表示将标准错误(STDERR)重定向到标准输出。1是标准输出的文件描述符,2是标准错误的文件描述符;

&表示将程序放到后台运行。

https://i-blog.csdnimg.cn/blog_migrate/cae99952addb7923e58d8f552c268639.png 上面运行用例中的进程号为17733

# 查看运行程序的工作zhuan
ps -ef | grep test.py

若想停止程序,可以使用下面语句:

kill -9  进程id