This question already has an answer here:

How can screen be used to start a new session and run a command within that session without killing that session?

 screen -S myScreenName runSomething

I tried the above command and it says

[screen is terminating]

Did it run the command then kill the screen? I would like the screen to be detached after running the command instead of killing it. How can that be done?

marked as duplicate by Jenny D, Andrew B, kasperd, womble Nov 27 '15 at 6:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Why are you using screen here at all, if the command is just going to exit immediately? – Michael Hampton Feb 27 '14 at 2:29
  • @MichaelHampton the command doesn't exit immediately, it runs a daemon that prints to stdout, so I would like to keep it in a screen session. I will be starting the screen session from an Ansible playbook. I don't know why screen terminates when I ran that command. – Nyxynyx Feb 27 '14 at 2:32
  • 1
    Then tell the daemon not to daemonize. – Michael Hampton Feb 27 '14 at 2:35
  • @MichaelHampton Great that works. Can screen be asked to detach after running the command? Tried -d but it says There is no screen to be detached matching myScreenName – Nyxynyx Feb 27 '14 at 2:50

This script prevent session killing:

screen -dmS test bash -c 'echo waiting 5 senconds...; sleep 5; exec bash'



to run a command and detach from the session:

screen -d -m runSomething
  • The screen still terminates when using this command. – Luc Jan 4 '15 at 23:34

If you keep forgetting the right letters that go after dash, in order to avoid revisiting this question, you might as well type:

screen -h

where you'll see:

-dmS name     Start as daemon: Screen session in detached mode.

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