For When You Can't Have The Real Thing
[ start | index | login ]
start > screen > Force Screen Detatch

Force Screen Detatch

Created by dave. Last edited by dave, 8 years and 331 days ago. Viewed 4,583 times. #2
[diff] [history] [edit] [rdf]
labels
attachments

Problem

I was running a screen session remotely and got disconnected somehow. When I connect back in and issue my reconnect-to-screen command, the session hangs for a long time before connectiong.

Discussion

What appears to happen is that when screen receives the force-detach signal, it is trying to notify the tty that holds it that it is about to leave. Since the tty is hung due to a dropped connection it has to wait for the timeout to happen (which is upwards of five minutes in some cases).

Solution

This script looks for a screen session that you own, and kills the bash on that TTY. This lets screen complete the disconnect, and you can reconnect normally.

This script is very crude. It won't work properly in environments where you have multiple screen sessions going. It expects exactly one process owned by you with 'screen' in its name. So if you name this script 'killscreen', it won't work.

#!/bin/bash
if [ ! -z "$STY" ] ; then
  echo Not a good idea to run this from inside screen
  exit 0
fi
PTS=`ps -ef | grep screen | grep -v grep | grep $LOGNAME | awk '{print $6}'`
if [ ! -z "$PTS" ] ; then
  PS=`ps -ef | grep $PTS | grep bash | awk '{print $2}'`
  if [ ! -z "$PS" ] ; then
    echo killing $PS
    kill -9 $PS
    screen -list
  fi
fi
no comments | post comment
This is a collection of techical information, much of it learned the hard way. Consider it a lab book or a /info directory. I doubt much of it will be of use to anyone else.

Useful:


snipsnap.org | Copyright 2000-2002 Matthias L. Jugel and Stephan J. Schmidt