I have a file opened in vi running in a terminal(xterm), if I directly closes the terminal without first closing the file then I can see the vi still running in the background(ps x). Now is there any way to attach that process i.e. vi to some other terminal so that I can continue my work on the file. I have also tried fd command but it fails.
|
|
|||
migrated from stackoverflow.com Dec 13 '10 at 7:12
|
You can try GNU screen. It is made for this purpose.
|
||||
|
|
No way to do that. Just kill the detached process. If you want to do this intentionally, have a look at the 'screen' command. This will not save you if your underlying shell dies though. |
|||
|
|
|
This is not possible “cleanly”. There are tools such as screen and tmux that create a remanent virtual terminal: you can start your program inside screen, detach the screen session, and later reattach the screen session on a different terminal. But that requires planning ahead. It is possible to use ptrace to fiddle with the process's file descriptors to reconnect them to another terminal. That doesn't work reliably because it might create inconsistencies in the process's data structures: some programs won't mind, others will crash. You can do this by attaching the program in a debugger and issue the right sequence of system calls (at least See also How can I pause up a running process over ssh, disown it, associate it to a new screen shell and unpause it?, View Script Over SSH?, Can I nohup/screen an already-started process?, Resume command running in dropped SSH session. |
|||
|
|
|
You can use GDB to attach a running process to a terminal. Here's a description spread across several answers to a question (particularly see the one by Mirek): Redirect STDERR / STDOUT of a process AFTER it's been started, using command line? |
|||
|
|
vi &detachs the process from the existing terminal – Rafe Kettler Dec 13 '10 at 6:02