I have a running program on a SSH shell. I want to pause it and be able to unpause its execution when I come back.
One way I thought of doing that was to transfer its ownership to a screen shell, thus keeping it running in there.
Is there a different way to proceed?
Best Answer
You can revoke “ownership” of the program from the shell with the
disown
built-in:However this only tells the shell not to send a
SIGHUP
signal to the program when the shell exits. The program will retain any connection it has with the terminal, usually as standard input, output and error streams. There is no way to reattach those to another terminal. (Screen works by emulating a terminal for each window, so the programs are attached to the screen window.)It is possible to reattach the filedescriptors to a different file by attaching the program in a debugger (i.e. using
ptrace
) and making it callopen
,dup
andclose
. There are a few tools that do this; this is a tricky process, and sometimes they will crash the process instead. The possibilities include (links collected from answers to How can I disown a running process and associate it to a new screen shell? and Can I nohup/screen an already-started process?):