The purpose of this article is to show you how to move a process from your traditional shell to a new screen session.
- The first thing to do is to suspend the process. In my case, mv can be suspended by typing ctrl+z.
- Secondly, resume the process in background:
- Now, we will detach the process from its parent (the shell). So, when the parent process will be terminated, the child (mv) will be able to continue. For this, we use the disown builtin:
$ disown mv
- Launch a screen session:
- As we are in a screen session, we will retrieve the mv process. To do so, we use the reptyr command which take a pid:
$ reptyr <pid>
- To avoid the tedious pid research, we can use the pgrep command:
$ reptyr $(pgrep mv)
Now the process is in a screen shell, we can safely detach our session and no longer worry about killing our X server or close our ssh connection.