1

I logged into the server using Putty/ssh started a process and walked away. Came back to find the putty session had timedout/terminated/become inactive. When I log back in the process is still there and running.

Is there anyway I can get connected back to either that session or that process?

1
1

No you can't. But you can use screen for that purpose, it creates a virtual terminal where you can run the process you want, then detach from it and reattach whenever you want.

  • Create a new screen:

    screen -S [session_name]

  • Detach from that session

    <Ctrl> + <A> then <D>

  • Reattach to a session:

    screen -r [session_name]

3
  • Screen is also great for doing some terminal magic, for example running multiple terminals on split screen or sharing terminal sessions. It's a must-have in my Linux toolbox.
    – gronostaj
    Jul 23 '14 at 18:05
  • Alternatively, the “modern way”: tmux
    – Daniel B
    Jul 23 '14 at 18:05
  • Yep, tmux seems nice too, but I don't know how to use it. Also detach is a program specifically dedicated to detach from and reattach to a terminal a process.
    – piernov
    Jul 23 '14 at 18:09
0

The tremendously useful reptyr utility does just this. Once installed, simply make a note of the PID of the process you want to regain control of and then run:

reptyr PID

Its author wrote a series of blog posts explaining some of the finer details.

Runs on Linux and FreeBSD, but the latter does not support the "TTY-stealing" feature invoked via the -T option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.