nohup
(no hang-up)命令用于在Linux中使進程忽略掛起(SIGHUP)信號,從而在用戶退出登錄后繼續運行
與命令直接組合使用:
nohup command &
這將在后臺運行command
,并將輸出重定向到名為nohup.out
的文件。
與管道(pipe)組合使用:
nohup command1 | command2 &
這將在后臺運行command1
,將其輸出作為command2
的輸入,并將command2
的輸出重定向到名為nohup.out
的文件。
與子shell組合使用:
nohup bash -c 'command1; command2' &
這將在后臺運行一個子shell,依次執行command1
和command2
,并將子shell的輸出重定向到名為nohup.out
的文件。
與&
符號組合使用:
command1 & nohup command2 &
這將在后臺分別運行command1
和command2
,并將它們的輸出都重定向到名為nohup.out
的文件。
與disown
命令組合使用:
nohup command & disown
這將在后臺運行command
,并將其從當前shell的作業表中移除,使其在用戶退出登錄后繼續運行。
請注意,nohup
命令通常與&
符號一起使用,以便在后臺運行進程。同時,為了避免輸出到終端,建議將輸出重定向到一個文件,如nohup.out
。