1

I have a program that runs in the foreground so I run it via a 'screen'. Is there a good start/stop/restart template for 'screen'? I need it to pass the commands to the screen and create it if it doesn't exist.

Will
  • 257
  • 4
  • 19

2 Answers2

1

I think you're slightly confused.

All screen does is allow you to detach it from the current terminal, and reattach at a later date.

You can however, start a process within screen, detached.

screen -d -m your_command_here

Tom O'Connor
  • 27,480
  • 10
  • 73
  • 148
  • I know, I am mainly looking for a basic template that would easy to modify to use screen. Along with how to create the screen if it doesn't exist. – Will Oct 12 '10 at 23:50
0

I'm not sure what you mean by "template for screen" but the -R option means "connect me to an existing screen or start a new one". To be useful you'll want something like screen -d -R -S myscreen. The -d option will detach it if it was already attached somewhere else, and "-S myscreen" will name your screen session so future screen -d -R -S myscreen commands will know which screen you're talking about.

Unfortunately, -d -R -S can't be used with -d -m, so you can't say "start a screen named myscreen in detached mode unless there's already a screen named myscreen". Once it's started, you'll have to use the ctrl-a ctrl-d command to detach it if you don't want it running in the foreground.

Anything after the options will be executed as a command in a new screen only, so you can execute screen -d -R -S myscreen /some/program to:
1) If a screen named myscreen exists, detach it from wherever it is and reattach it here
2) If the screen does not exist, create it and execute /some/program in it.

Note that if you run a command in screen, when that command exits so will screen.

DerfK
  • 19,493
  • 2
  • 38
  • 54