前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nohup和&的区别与关系

nohup和&的区别与关系

作者头像
py3study
发布2020-01-02 16:30:51
4650
发布2020-01-02 16:30:51
举报
文章被收录于专栏:python3python3
# test_nohup.py
import time
time.sleep(1000)
print('test')

& 是shell的命令,如果我们执行python test_nohup.py,就会直接返回shell给用户,且用户不能再进行输入。

& puts the job in the background, that is, makes it block on attempting to read input, and makes the shell not wait for its completion.

但如果我们关闭terminal,process将被关闭。只是失去了process从terminal获得输入的能力。

(jd) ubuntu@vmXXX:~$ python3 test_nohup.py &
[1] 11698

nohup test_nohup.py

nohup disconnects the process from the terminal, redirects its output to nohup.out and shields it from SIGHUP.

我们仍然可以使用ctrl+c将进程(process)杀死,但如果我们关闭terminal,process仍然在后台进行。但我们无法立刻获得shell的交互能力。

将两者结合起来,就能让程序在后台运行的同时,我们也能获得交互shell的能力。

nohup python3 test_nohup.py > logfile.log &

参考链接: http://unix.stackexchange.com... https://segmentfault.com/q/10...

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-10-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档