It's hard to summarise my question in the title, so here is the actual situation. I am running picam to use my camera module as a security camera. I don't need it when I'm in the house, so before I leave I SSH into my Pi, start my web server (which hosts images that picam generates if motion is detected) and run python picam.py. The terminal is then running the script - I have to Ctrl + C out of it to stop it.

If I SSH in later, I am in the terminal again, but one in which the script isn't running. Is the script still running in a separate terminal in memory? Does it stop when I SSH in again? Can I access that running terminal? What happens if I run the script again from the new terminal?


Install screen or tmux (both are available in raspbian repos). First start screen or tmux from your first ssh session, and start other programs from a screen or tmux window. You can then quit your first ssh session. Your programs will continue to run. You can later open another ssh session and reattach to the first tmux window.

  • I've tried this, but perhaps I'm doing something wrong. I ssh in, run tmux, run picam.py, then quit out. When I go back in with a new SSH, I run tmux again, but it's just a new session. Any windows I created in the first tmux session are lost. – user8543 Jul 16 '14 at 16:45
  • 2
    use ctrl-b d to detach and tmux att to attach to the existing session. – Craig Jul 16 '14 at 18:10
  • Never mind, I've worked it out. For future reference, tmux opens separate sessions which can be listed with tmux ls. You can attach (enter) to a session with tmux a -t <number> – user8543 Jul 16 '14 at 18:14

Yes, the script is still running som the session you had - no, it does not stop when you open a new connection. You can't really access that session from another one, but you can manipulate what it's doing - try ps -e. If you run the script in the new session you will start a new instance of the script - exactly what will happen in this case is hard to tell. Try it.

What you want might be to create a service - that is one instance of a script that runs and can be started or stopped from different places. Have a look at http://www.linux.com/news/enterprise/systems-management/8116-an-introduction-to-services-runlevels-and-rcd-scripts

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.