I've got a screen session running which I would like to :quit, but I can't because when I try to re-attach, I get an error saying it can't open my terminal. I'm sure I could kill the daemon or something, but I need to learn the "right" way, as well as what's actually going on.

 daniel@DELIRIUM:~/server1/bin/plugins$ screen -list
 There is a screen on:
        1424.pts-0.DELIRIUM     (06/23/2011 01:18:14 PM)        (Detached)
 1 Socket in /var/run/screen/S-daniel.

 daniel@DELIRIUM:~/server1/bin/plugins$ screen -r 1424
 Cannot open your terminal '/dev/pts/0' - please check.

Also, what is a socket? The more you can dumb it down the better.


You don't own your TTY for some reason. Did you use su to change to that user from another user? Normally the TTY is owned by the person who originally logs into that terminal.

There's a neat trick to fix this (other than changing the permissions on the /dev/pts/0 file by the user who originally logged in), the bsdutils package has a program called script which, when run, acts something like a keylogger, saving both what you type and what programs print. It starts another shell and allocates another pseudotty for that shell in order to record all this, so if you run script /dev/null it will create a new pseudotty with proper permissions, and start recording everything on it to /dev/null. Then you will be able to use screen to reattach your session.

As for "sockets", this is screen's term for the named pipe files (also known as FIFOs) in /var/run/screen/S-username, eg

prw------- 1 derf derf 0 Jun 23 22:42 30029.pts-0.server

When you first start screen, this pipe file is created in order to connect the screen process you are using to view the displays with the background screen process (usually renamed SCREEN) the programs are actually running in. When you run screen -r, the screen process you are running opens this pipe to talk to the background screen process.


Something weird is going on here. Can you please paste the output of :

   ls -l /dev/pts/0
   id

A socket in this case is a form of interprocess communication, its a file on the filesystem that forms a channel between the process and with... other processes. So your screen "client" is talking to the other running screen instance, and this is how the magic of screen works. Sockets are confusing concepts in Linux because traditionally people think of the word socket as meaning as Network Sockets. Its a hard concept to dumb down, it fits into a range of other inter-process communication channels best explained by the book "Advanced Programming in the UNIX Environment".