How can I disown a running process and associate it to a new screen shell?

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?

ANSWER:-

You can revoke “ownership” of the program from the shell with the disown built-in:
# press Ctrl+Z to suspend the program
bg
disown
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 be possible to reattach the filedescriptors to a different file by attaching the program in a debugger (i.e. using ptrace) and making it call opendup and close. 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?):
  • grab (and the more ambitious cryopid)
  • neercs
  • retptyr
  • retty

0 comments:

Post a Comment

Don't Forget to comment