nohup
(no hang-up)命令允許您在后臺運行程序,即使關閉終端或斷開連接,程序也會繼續運行
nohup
一起使用,并在命令末尾添加&
符號。例如:nohup your_command &
這將在后臺運行your_command
,并將輸出重定向到名為nohup.out
的文件。
nohup your_command > output_file 2>&1 &
這將把標準輸出和錯誤輸出都重定向到output_file
。
nohup sh -c 'command1; command2' &
這將在后臺依次運行command1
和command2
。
ps
命令。例如,要查找與your_command
相關的進程,可以運行:ps aux | grep your_command
kill
命令。首先,使用ps
命令找到進程ID(PID),然后運行:kill PID
將PID
替換為實際的進程ID。
總之,nohup
命令可以與各種命令結合使用,以便在后臺運行程序并確保它們在關閉終端或斷開連接后繼續運行。