I use a VPN tunnel to connect to my work network and then SSH to connect to my work PC running cygwin. Once logged in I can attach to a screen session and everything works great.

Now, after a while, I walk away from my computer and sooner or later, the VPN tunnel times out. The SSH connection on each end eventually times out and then I eventually come back to my computer to do some work. Theoretically, this should be a simple matter of just restarting the VPN, reconnecting via SSH, and then running "screen -r -d".

However apparently when the sshd daemon times out on the cygwin PC, it leaves the screen session in some kind of hung state. I can reproduce a similar hung state by clicking the close box on a cygwin bash shell window while it's running a screen session.

Is there any way to get the screen session to recover once this has happened, so that I don't lose anything?


With a great deal of experimentation, I was able to recover the screen session as follows:

  1. Lookup the PID of the server screen process: ps | grep screen
  2. Send the server a HUP signal: kill -1 <PID>
  3. Run a screen client: screen -r -d
| improve this answer | |
  • Thank you! I thought that not being able to reattach was an inherent limitation of Cygwin's screen. This works beautifully! When I execute ps | grep screen the first time, though, I see two processes, a parent and a child. Your solution works iff I send the HUP signal to the child. – garyjohn Jan 12 '11 at 3:06
  • @garyjohn: I believe that the child is the server if you haven't detached when you first launched screen. At least that's what it looked like when I viewed it in Process Explorer. When I detached, the parent process went away and the child remained. Is that what you're seeing? – Mikey Jan 12 '11 at 6:24
  • My test wasn't exactly the same as yours, but I think the results are the same. I ssh'd from another computer using PuTTY, executed screen, then closed PuTTY. That simulated the rude disconnections I usually suffer. Then I ssh'd as before and executed pstree, which showed the two screen instances still running. When I sent HUP to the child, the parent died and the child became inherited by PID 1. – garyjohn Jan 12 '11 at 7:07

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.