Linux 將運行中的任務轉後台並在會話關閉後繼續運行

假如我想要在服務器上把文件從一個硬盤考到另一個硬盤, 就要用到 cp/dd/rsync 命令對吧, 我想要讓服務器去運行這個命令, 我可以直接把終端關掉, 這時候第一個想起來就是 nohup [命令] &. nohup 意思是讓終端掛掉時進程不結束, & 的意思讓進程在後台執行.

但是如果我在拷貝之前沒想這麼多, 開始了之後才發現要運行好久, 這個時候應當怎麼辦呢? 我在中文互聯網上並沒有找到相關的問題/答案. 反倒是在 Stack Overflow 上找到了.

原問題及回答:

https://stackoverflow.com/questions/625409/how-do-i-put-an-already-running-process-under-nohup

  1. 按 Ctrl + Z 暫停程序
  2. 輸入 bg 讓暫停的程序在後台執行
  3. 輸入 jobs 查看程序 id (如果之前沒有執行類似操作過就是 1)
  4. 輸入 disown -h [id] 從 shell 的作業列表移除指令

Thumbnail: Sea Shell by Shyam B
If using the image violates your rights, or there’s anything related to copyright laws, please contact me at [email protected], I will deal with them immediately.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *