Stealing and reattaching a running process

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

sudo reptyr -T $PID

From man reptyr:

-T

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x