Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The GNU Screen manual says:

When a program terminates, screen (per default) kills the window that contained it.

The (per default) suggests that you can change this option, so that a program terminating won't kill the window it's in. How to I change this behavior?

share|improve this question

migrated from Nov 29 '11 at 21:26

This question came from our site for professional and enthusiast programmers.

Since you tagged bash, you need to be aware that your shell is also a program you need to separately exit. This is mostly relevant if you run a program directly on a screen without a shell. – Daniel Beck Nov 29 '11 at 21:28
Are you saying you want to be able to view the contents of the screen once the program has exited, or somehow do other things with the window? – Paul Nov 29 '11 at 22:54
@Paul The latter. Currently I start a bunch of local development servers through my .screenrc, but that means if I kill one then the window closes. Would be nice to be able to then restart it in the same window it was it. – Dan Nov 30 '11 at 14:27
Ok got it - answer below. – Paul Nov 30 '11 at 22:51
up vote 8 down vote accepted

try to use zombie or defzombie. I am using the following settings.

# don't remove windows from the window list as soon as window process exits.
zombie kr #  k: destory window, r: resurrect window
share|improve this answer
Great find! That's one stupid command name. I searched the man page with every term I could think of, and didn't find this. – Daniel Beck Dec 6 '11 at 4:16
This is almost exactly what I'm looking for (and certainly close enough) - if only it would r automatically... – Dan Dec 6 '11 at 14:30

I would suggest starting screen with a "shell" first and the running your command so when it finished you are returned to your shell inside screen and can see the output of your command. (You may want do disable the autologout feature of the shell to avoid it closing after some time)

Otherwise, I did a read on the manpage of screen again and cannot found another option for keeping a window open after his main command has finished.

share|improve this answer

A screen window exits when the program it is running exits. This is because screen is itself not a shell, so once the program exits, there is nothing more that can be done with the window. You cannot launch a new program, as there is nothing remaining under that terminal session that could launch a program.

A newly created screen window will by default run bash (or whatever your nominated shell is). As bash is a shell, you can launch any number of programs from it, and when they exit, they return to bash. Then another program can be launched. So a window running bash will behave as you describe. It is only when bash itself exits will the window close.

Note that this is the same behaviour as any terminal session, once the last program exits, the terminal session ends (with a normal terminal, this session is then respawned if set to by init and you are then presented with a login screen).

This is a bit hacky, but normally when you start screen with a command, the command completing ends the window. However, if you also start bash with command using the -c option, bash will also exit once the command exits.

So if we want bash to run a command but stick around once the command ends, we need to run the command as part of the bash initilisation process.

For example, if you create a new file "startserver1" containing the commands needed to start the server:

#start the server
ls -la

Then run screen with bash, initialising with the startserver1 file:

screen bash --init-file startserver1

This will invoke screen, starting bash, initalising bash with your server start script. Once the server ends, you are left in the bash session within the screen window.

share|improve this answer
It'd keep the output accessible though. – Daniel Beck Nov 30 '11 at 22:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.