Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently running a backup and it now needs to be transferred to detachable one like on tmux/screen. Is there a way to do this when the command is currently running?

I can send the command the background by pressing ctrl+z and put it back up by issuing a fg command. but I do not know if that session can go back when i exit the terminal.

share|improve this question
There is no way to do that. You have to start the command from within a screen (or other) session for it to be detachable. – Dan D. Jul 24 '13 at 3:16

This works, most of the time:

(prerequisites: have reptyr and tmux/screen installed; you'll be able to find them with apt-get or yum, depending on your platform)

  1. Use Ctrl-Z to suspend the process.

  2. Resume the process in the background with bg

  3. Find the process ID of the background process with jobs -l

    You'll see something similar to this:

    [1]+ 11475 Stopped (signal) yourprocessname
  4. Disown the job from the current parent (shell) with disown yourprocessname

  5. Start tmux (preferred), or screen.

  6. Reattach the process to the tmux/screen session with reptyr:

    reptyr 11475
  7. Now you can detach the multiplexer (default Ctrl-B D for tmux, or Ctrl-A D for screen), and disconnect SSH while your process continues in tmux/screen.

  8. Later when you connect with SSH again, you can then attach to your multiplexer (e.g. tmux attach).

share|improve this answer
Unfortunately after running sudo reptyr 1430 I still got: "...[-] Unable to open the tty in the child. Unable to attach to pid 1430: Permission denied" – Daryl Spitzer Dec 12 '14 at 18:55
You may find some success with the -L option e.g. reptyr -L 1430 in your case. – cgseller Apr 21 at 19:06
Run this when necessary: echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope – Yanhao May 6 at 11:39

you can use disown to detach the job from its terminal, if that command is available.

it is safer to run it with nohup to start with though.

share|improve this answer
Can you expand on this? What do you mean to start with it nohup? How does disowning a process work? – Darth Android Jul 24 '13 at 15:40
disown detaches the background process (that you put into background with control-z) from the terminal so the process will continue after the terminal is gone. you can just type disown after control-z, if the command is found. however this is in theory and may not work reliably. next time it is safer by adding nohup in the front of your program so that you can exit the terminal safely. – johnshen64 Jul 24 '13 at 15:50
I've found 'disown' to be pretty unreliable, as mentioned. nohup isn't really hugely better. reptyr might be a solution however. – anastrophe Sep 20 '13 at 23:58
This does not answer the question. The question is not only "how do I close the terminal without killing the backup", it is "how do I resume it later". To which the correct answer is "you can't". – Gabe Nov 11 '13 at 23:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .