Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
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
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

2 Answers 2

to run a command and detach from the session:

screen -d -m runSomething
share|improve this answer
The screen still terminates when using this command. – Luc Jan 4 at 23:34

This script prevent session killing:

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


share|improve this answer

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.