If I use Ctrl-C in a screen I ran the "normal way" using screen -S screen_name, it behaves as expected meaning it will interrupt whatever command the screen is running but won't terminate the screen itself.

However, when I run screen in detached mode using screen -dmS screen_name command, it works fine but when I reattach the screen, Ctrl-C will terminates the screen itself.

How can I prevent Ctrl-C from terminating the screen?


Screen exits when the command it is running finishes.

In your first example you don't specify a command, so your default shell will be started.

In your second example, you don't specify a shell so your command is run directly. When that command receives the Ctrl-C, it will quit and so the screen will close.

Depending on what you want to achieve, you can use the zombie, defzombie or onerror options to screen to make the window stick around after the command has quit.

Alternatively, this answer contains a suggestion for keeping a bash shell open after an initial script terminates.

  • Thanks, now it's clear. I basically wanted bash to run after my command is terminated so I ended up doing: screen -dmS screen_name bash -c 'command;exec bash' – Cyrlop Oct 17 '17 at 11:58

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.