nohup 的用途就是讓提交的命令忽略 hangup 信號。讓咱們先來看一下 nohup 的幫助信息python
NOHUP(1) BSD General Commands Manual NOHUP(1) NAME nohup -- invoke a utility immune to hangups SYNOPSIS nohup [--] utility [arguments] DESCRIPTION The nohup utility invokes utility with its arguments and at this time sets the signal SIGHUP to be ignored. If the standard output is a terminal, the standard output is appended to the file nohup.out in the current directory. If stan- dard error is a terminal, it is directed to the same place as the standard output. Some shells may provide a builtin nohup command which is similar or identical to this utility. Consult the builtin(1) manual page.
可見,nohup 的使用是十分方便的,只需在要處理的命令前加上 nohup 便可,標準輸出和標準錯誤缺省會被重定向到 nohup.out 文件中。通常咱們可在結尾加上"&"來將命令同時放入後臺運行,也可用">filename 2>&1"來更改缺省的重定向文件名。shell
Lawrences-MBP:~ Lawrence$ nohup python test.py &
另外,python在print時,有時會等待緩衝區滿了纔打印數據,這時使用 python -u 能夠強制stdin,stdout和stderr變成無緩衝,當即輸出。app