It's sunday and I left an instance of R running in the office. The script finished running, and I would like to save my workspace without going to the office. I can ssh to the computer, but I have not run the program into screen.

Is there a way, over ssh, to disown the process (I don't have access to jobsid of the terminal the program is running on!) and reattach it with say, reptyr? Reptyr and reptyr -T don't work without previously disowning the process

28845 3diag       20   0  139.3m  10.4m   0.0  0.1   0:12.06 S  `- urxvtd                                                                                      
 5327 3diag       20   0   16.4m   4.6m   0.0  0.1   0:00.02 S      `- bash                                                                                    
 5335 3diag       20   0 3499.3m 3.244g   0.0 43.3 171:57.89 S          `- R 

The unique part of my question is that I explicitly require to detach a program without having access to the terminal in which it was created.

  • the reptyr man page does not say you have to disown the process first. It says you may want to. – meuh May 1 '16 at 11:52
  • Still, I get an error when I try that – Three Diag May 1 '16 at 11:52
  • reptyr 28845 [-] Process 28828 (xmonad-x86_64-l) shares 28845's process group. Unable to attach. (This most commonly means that 28845 has suprocesses). Unable to attach to pid 28845: Invalid argument Similarly: reptyr -T 28845 [-] Child is not connected to a pseudo-TTY. Unable to steal TTY. Unable to attach to pid 28845: Invalid argument – Three Diag May 1 '16 at 11:57
  • similarly, if I try with the child process (which is the one I want to actually get to) reptyr 5335 Unable to attach to pid 5335: Operation not permitted The kernel denied permission while attaching. If your uid matches the target's, check the value of /proc/sys/kernel/yama/ptrace_scope. For more information, see /etc/sysctl.d/10-ptrace.conf – Three Diag May 1 '16 at 11:57
  • 1
    Don't try to attach to urxvtd, it's just a daemon. Did you look into the files mentioned by the second invocation? Please update the post instead of commenting. – Alexander Batischev May 1 '16 at 12:17

Invocation of reptyr is sufficient to detach the terminal, but has to be

sudo reptyr -T $PID

From man reptyr:


Use an alternate mode of attaching, "TTY-stealing".

In this mode, reptyr will not ptrace(2) the target process, but will attempt to discover he terminal emulator for that process' pty, and steal the master end of the pty.

This mode is more reliable and flexible in many circumstances (for instance, it can attach all processes on a tty, rather than just a single process).

However, as a downside, children of sshd(8) cannot be attached via -T unless reptyr is run as root. See ⟨https://blog.nelhage.com/2014/08/new-reptyr-feature-tty-stealing/⟩ for more information about tty-stealing.

Not the answer you're looking for? Browse other questions tagged or ask your own question.