question about using screen
in order to make sure my server will be still running after I leave ssh, I have to use screen.
I type screen and hti ctrl + A C to create a new screen window.
And I run my server and use ctrl+A d to detach
Things work fine, but I don't know how to kill a window.
I use screen -r xxxxx to reattach to that window and hit ctrl+A K
I thought I killed that window, but when I use screen -ls, I can still see it there, it says that window is detached.
but when I use screen -r xxx to reconnect to that window, I saw error:
there is no screen to be resumed.
So basically, I can create a new window, but I cannot kill a window, so my windows are getting more and more.
How am I suppose to kill a screen window?
3 Replies
To clean up dead screen windows, use "screen -wipe" (no quotes). That should clean out any windows that were killed but are still open.
Also, if you have only one screen detached, you can reattach with "screen -r" (without xxxx). Faster.
You can think of screen as a "window manager". You can open many windows open in one instance of screen. When you do ctrl-a c then you open a new window, when you do ctrl-a K then you close a window. (NOTE: exiting the shell you open in the window will also close the window). You can see what windows you have open with ctrl-a w. For example, I have these windows open
0 spam 1 news 2 ksh 3* ksh 4- ksh 5 ksh 6 daffy
Closing a window does not stop the screen session; screen will die automatically when the last window it manages closes.
Now you can also have multiple instances of screen running at the same time. This is what you see when you run "screen -ls"; all the different screen instances.
From here you can see that ctrl-a K will not close screen down, unless you kill the last window inside a screen session.
So, if you have a number of detached screen sessions on the machine you can attach to one of them ("screen -r") and then see the windows it manages (ctrl-a w). You can then switch between the windows (ctrl-a 0 through ctrl-a 9) and close each window. When you close the last window then that screen instance will shutdown. You can then move onto the next detached session (if any) and tidy that up.
Finally, screen can get confused (normally this is due to a reboot or crash or bug) and leave things behind that it lists as detached, but without any screen session running. That can lead to the "no session" errors. These can be cleaned up, as others have mentioned, with the "-wipe" option.