1

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?

asked Jul 16, 2014 at 11:44

2 Answers 2

3

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.

answered Jul 16, 2014 at 13:14
3
  • 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. Commented Jul 16, 2014 at 16:45
  • 2
    use ctrl-b d to detach and tmux att to attach to the existing session. Commented Jul 16, 2014 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> Commented Jul 16, 2014 at 18:14
2

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

answered Jul 16, 2014 at 12:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.