要使命令再後臺一直運行的話 需要用到 nohup命令
nohup會不掛斷的運行,但不是後臺運行 需要使用 & 才能永久再後臺運行
nohup會將運行日誌寫入到nohup.out文件中,但是我並不想讓他寫入這個文件中,所以可以指定文件
將日誌寫入ass.log如:
nohup node internalTask.js > ass.log &操作系統中有三個常用的流:
0:標準輸入流 stdin
1:標準輸出流 stdout
2:標準錯誤流 stderr一般用> ass.log 實際是1 > ass.log 的省略用法 ; < ass.log 。實際是 0<ass.log 的省略用法
用法:
nohup node internalTask.js > ass.log 2>&1 &
2>&1的意思
把標準錯誤流(2)重定向到標準輸出流(1) ,而1是輸出到ass.log文件中 所以是1 +2 都導入到ass.log中 ;至於爲什麼需要將標準錯誤重定向到標準輸出的原因,那就歸結爲標準錯誤沒有緩衝區,而stdout有。這就會導致 >output 2>output 文件output被兩次打開,而stdout和stderr將會競爭覆蓋,這肯定不是我門想要的.
& :在後臺運行