2

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

2 Answers 2

2

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, 2014 at 18:05
  • Alternatively, the “modern way”: tmux
    – Daniel B
    Jul 23, 2014 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, 2014 at 18:09
1

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.

1
  • Good news. The support for the -T option has been added since version 0.8.0.
    – Bruce
    Apr 20, 2023 at 17:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .