nohup和&的區別與關係

# test_nohup.py
import time
time.sleep(1000)
print('test')

& 是shell的命令,若是咱們執行python test_nohup.py,就會直接返回shell給用戶,且用戶不能再進行輸入。python

& 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.shell

但若是咱們關閉terminal,process將被關閉。只是失去了process從terminal得到輸入的能力。ubuntu

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

nohup test_nohup.pysegmentfault

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

咱們仍然能夠使用ctrl+c將進程(process)殺死,但若是咱們關閉terminal,process仍然在後臺進行。但咱們沒法馬上得到shell的交互能力。code

將二者結合起來,就能讓程序在後臺運行的同時,咱們也能得到交互shell的能力。進程

nohup python3 test_nohup.py > logfile.log &

參考連接:
http://unix.stackexchange.com...
https://segmentfault.com/q/10...terminal

相關文章
相關標籤/搜索